unhead 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -14
- package/dist/index.mjs +12 -14
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -289,7 +289,7 @@ function processTemplateParams(s, config) {
|
|
|
289
289
|
val = config[token];
|
|
290
290
|
return val || (preserveToken ? token : "");
|
|
291
291
|
};
|
|
292
|
-
let template = s.replace(/%(\w+\.?\w
|
|
292
|
+
let template = s.replace(/%(\w+\.?\w*)%/g, replacer()).replace(/%(\w+\.?\w*)/g, replacer(true)).trim();
|
|
293
293
|
if (config.separator) {
|
|
294
294
|
if (template.endsWith(config.separator))
|
|
295
295
|
template = template.slice(0, -config.separator.length).trim();
|
|
@@ -305,19 +305,17 @@ function TemplateParamsPlugin() {
|
|
|
305
305
|
"tags:resolve": (ctx) => {
|
|
306
306
|
const { tags } = ctx;
|
|
307
307
|
const title = tags.find((tag) => tag.tag === "title")?.textContent;
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
}
|
|
308
|
+
const idx = tags.findIndex((tag) => tag.tag === "templateParams");
|
|
309
|
+
const params = idx !== -1 ? tags[idx].textContent : {};
|
|
310
|
+
params.pageTitle = params.pageTitle || title || "";
|
|
311
|
+
delete tags[idx];
|
|
312
|
+
for (const tag of tags.filter(Boolean)) {
|
|
313
|
+
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string")
|
|
314
|
+
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
315
|
+
else if (tag.tag === "meta" && typeof tag.props.content === "string")
|
|
316
|
+
tag.props.content = processTemplateParams(tag.props.content, params);
|
|
317
|
+
else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && typeof tag.innerHTML === "string")
|
|
318
|
+
tag.innerHTML = processTemplateParams(tag.innerHTML, params);
|
|
321
319
|
}
|
|
322
320
|
ctx.tags = tags.filter(Boolean);
|
|
323
321
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -288,7 +288,7 @@ function processTemplateParams(s, config) {
|
|
|
288
288
|
val = config[token];
|
|
289
289
|
return val || (preserveToken ? token : "");
|
|
290
290
|
};
|
|
291
|
-
let template = s.replace(/%(\w+\.?\w
|
|
291
|
+
let template = s.replace(/%(\w+\.?\w*)%/g, replacer()).replace(/%(\w+\.?\w*)/g, replacer(true)).trim();
|
|
292
292
|
if (config.separator) {
|
|
293
293
|
if (template.endsWith(config.separator))
|
|
294
294
|
template = template.slice(0, -config.separator.length).trim();
|
|
@@ -304,19 +304,17 @@ function TemplateParamsPlugin() {
|
|
|
304
304
|
"tags:resolve": (ctx) => {
|
|
305
305
|
const { tags } = ctx;
|
|
306
306
|
const title = tags.find((tag) => tag.tag === "title")?.textContent;
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
}
|
|
307
|
+
const idx = tags.findIndex((tag) => tag.tag === "templateParams");
|
|
308
|
+
const params = idx !== -1 ? tags[idx].textContent : {};
|
|
309
|
+
params.pageTitle = params.pageTitle || title || "";
|
|
310
|
+
delete tags[idx];
|
|
311
|
+
for (const tag of tags.filter(Boolean)) {
|
|
312
|
+
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string")
|
|
313
|
+
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
314
|
+
else if (tag.tag === "meta" && typeof tag.props.content === "string")
|
|
315
|
+
tag.props.content = processTemplateParams(tag.props.content, params);
|
|
316
|
+
else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && typeof tag.innerHTML === "string")
|
|
317
|
+
tag.innerHTML = processTemplateParams(tag.innerHTML, params);
|
|
320
318
|
}
|
|
321
319
|
ctx.tags = tags.filter(Boolean);
|
|
322
320
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.7",
|
|
5
5
|
"packageManager": "pnpm@7.27.1",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"hookable": "^5.4.2",
|
|
34
34
|
"packrup": "^0.1.0",
|
|
35
|
-
"@unhead/dom": "1.1.
|
|
36
|
-
"@unhead/schema": "1.1.
|
|
37
|
-
"@unhead/shared": "1.1.
|
|
35
|
+
"@unhead/dom": "1.1.7",
|
|
36
|
+
"@unhead/schema": "1.1.7",
|
|
37
|
+
"@unhead/shared": "1.1.7"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "unbuild .",
|