unhead 1.1.6 → 1.1.8
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 +18 -20
- package/dist/index.mjs +18 -20
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -279,17 +279,17 @@ const DedupesTagsPlugin = (options) => {
|
|
|
279
279
|
};
|
|
280
280
|
|
|
281
281
|
function processTemplateParams(s, config) {
|
|
282
|
-
const
|
|
283
|
-
if (token === "pageTitle" || token === "s")
|
|
284
|
-
return config.pageTitle;
|
|
282
|
+
const sub = (_, token) => {
|
|
285
283
|
let val;
|
|
286
|
-
if (token
|
|
287
|
-
val =
|
|
284
|
+
if (token === "pageTitle" || token === "s")
|
|
285
|
+
val = config.pageTitle;
|
|
286
|
+
else if (token.includes("."))
|
|
287
|
+
val = token.split(".").reduce((acc, key) => acc[key] || "", config);
|
|
288
288
|
else
|
|
289
289
|
val = config[token];
|
|
290
|
-
return val ||
|
|
290
|
+
return val || "";
|
|
291
291
|
};
|
|
292
|
-
let template = s.replace(/%(\w
|
|
292
|
+
let template = s.replace(/%(\w+\.+\w+)/g, sub).replace(/%(\w+)/g, sub).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
|
@@ -278,17 +278,17 @@ const DedupesTagsPlugin = (options) => {
|
|
|
278
278
|
};
|
|
279
279
|
|
|
280
280
|
function processTemplateParams(s, config) {
|
|
281
|
-
const
|
|
282
|
-
if (token === "pageTitle" || token === "s")
|
|
283
|
-
return config.pageTitle;
|
|
281
|
+
const sub = (_, token) => {
|
|
284
282
|
let val;
|
|
285
|
-
if (token
|
|
286
|
-
val =
|
|
283
|
+
if (token === "pageTitle" || token === "s")
|
|
284
|
+
val = config.pageTitle;
|
|
285
|
+
else if (token.includes("."))
|
|
286
|
+
val = token.split(".").reduce((acc, key) => acc[key] || "", config);
|
|
287
287
|
else
|
|
288
288
|
val = config[token];
|
|
289
|
-
return val ||
|
|
289
|
+
return val || "";
|
|
290
290
|
};
|
|
291
|
-
let template = s.replace(/%(\w
|
|
291
|
+
let template = s.replace(/%(\w+\.+\w+)/g, sub).replace(/%(\w+)/g, sub).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.8",
|
|
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.8",
|
|
36
|
+
"@unhead/schema": "1.1.8",
|
|
37
|
+
"@unhead/shared": "1.1.8"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "unbuild .",
|