Skip to content

Commit 869d87c

Browse files
authored
Merge pull request #6 from thefrontside/cl/meta-content-tags
✨ replace absolute `meta content="${url}"` properties with base url
2 parents 06dfed2 + 50a35ac commit 869d87c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@frontside/staticalize",
3-
"version": "0.2.0",
3+
"version": "0.2.2",
44
"exports": {
55
".": "./mod.ts",
66
"./cli": "./main.ts"

staticalize.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ function useDownloader(opts: DownloaderOptions): Operation<Downloader> {
159159
}
160160
}
161161

162+
let withContents = selectAll("[content]", html);
163+
for (let element of withContents) {
164+
let attr = String(element.properties.content);
165+
if (attr.startsWith(host.origin)) {
166+
yield* downloader.download(attr, source);
167+
let url = new URL(attr);
168+
url.host = base.host;
169+
url.port = base.port;
170+
url.protocol = base.protocol;
171+
element.properties.content = url.href;
172+
}
173+
}
174+
162175
yield* call(async () => {
163176
let destdir = dirname(destpath);
164177
await ensureDir(destdir);

test/staticalize.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,15 @@ describe("staticalize", () => {
193193
<html>
194194
<head>
195195
<link rel="canonical" href="${host}"/>
196-
<script src="${host}main.js"/>
196+
<meta property="og:url" content="${host}image.png"/>
197+
<script src="${host}main.js"></script>
197198
</head>
198199
<body></body>
199200
</html>
200201
`;
201202
app.get("/", (c) => c.html(html))
202203
.get("/alt", (c) => c.html(html))
204+
.get("/image.png", (c) => c.text(""))
203205
.get("/main.js", (c) => c.text("console.log('hi')"))
204206
.get(...sitemap(["/"]));
205207

@@ -215,6 +217,9 @@ describe("staticalize", () => {
215217
await expect(content("test/dist/index.html")).resolves.toMatch(
216218
`<script src="https://fs.com/main.js">`,
217219
);
220+
await expect(content("test/dist/index.html")).resolves.toMatch(
221+
`<meta property="og:url" content="https://fs.com/image.png">`,
222+
);
218223
});
219224
});
220225

0 commit comments

Comments
 (0)