unhead 1.1.28 → 1.1.30
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 +22 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +22 -18
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -262,15 +262,17 @@ function DedupesTagsPlugin() {
|
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
function processTemplateParams(s,
|
|
265
|
+
function processTemplateParams(s, p) {
|
|
266
|
+
if (typeof s !== "string")
|
|
267
|
+
return s;
|
|
266
268
|
function sub(token) {
|
|
267
269
|
if (["s", "pageTitle"].includes(token))
|
|
268
|
-
return
|
|
270
|
+
return p.pageTitle;
|
|
269
271
|
let val;
|
|
270
272
|
if (token.includes(".")) {
|
|
271
|
-
val = token.split(".").reduce((acc, key) => acc ? acc[key] || void 0 : void 0,
|
|
273
|
+
val = token.split(".").reduce((acc, key) => acc ? acc[key] || void 0 : void 0, p);
|
|
272
274
|
} else {
|
|
273
|
-
val =
|
|
275
|
+
val = p[token];
|
|
274
276
|
}
|
|
275
277
|
return typeof val !== "undefined" ? val || "" : false;
|
|
276
278
|
}
|
|
@@ -286,12 +288,13 @@ function processTemplateParams(s, config) {
|
|
|
286
288
|
s = s.replace(new RegExp(`\\${token}(\\W|$)`, "g"), `${re}$1`).trim();
|
|
287
289
|
}
|
|
288
290
|
});
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
291
|
+
const sep = p.separator;
|
|
292
|
+
if (s.includes(sep)) {
|
|
293
|
+
if (s.endsWith(sep))
|
|
294
|
+
s = s.slice(0, -sep.length).trim();
|
|
295
|
+
if (s.startsWith(sep))
|
|
296
|
+
s = s.slice(sep.length).trim();
|
|
297
|
+
s = s.replace(new RegExp(`\\${sep}\\s*\\${sep}`, "g"), sep);
|
|
295
298
|
}
|
|
296
299
|
return s;
|
|
297
300
|
}
|
|
@@ -303,7 +306,8 @@ function TemplateParamsPlugin() {
|
|
|
303
306
|
const title = tags.find((tag) => tag.tag === "title")?.textContent;
|
|
304
307
|
const idx = tags.findIndex((tag) => tag.tag === "templateParams");
|
|
305
308
|
const params = idx !== -1 ? tags[idx].props : {};
|
|
306
|
-
params.
|
|
309
|
+
params.separator = params.separator || "|";
|
|
310
|
+
params.pageTitle = processTemplateParams(params.pageTitle || title || "", params);
|
|
307
311
|
for (const tag of tags) {
|
|
308
312
|
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string") {
|
|
309
313
|
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
@@ -609,7 +613,7 @@ function packMeta(inputs) {
|
|
|
609
613
|
});
|
|
610
614
|
}
|
|
611
615
|
|
|
612
|
-
const OpenGraphInputs = ["Image", "Video", "Audio"];
|
|
616
|
+
const OpenGraphInputs = ["og:Image", "og:Video", "og:Audio", "twitter:Image"];
|
|
613
617
|
const SimpleArrayUnpackMetas = ["themeColor"];
|
|
614
618
|
const ColonPrefixKeys = /^(og|twitter|fb)/;
|
|
615
619
|
const PropertyPrefixKeys = /^(og|fb)/;
|
|
@@ -640,32 +644,32 @@ function changeKeyCasingDeep(input) {
|
|
|
640
644
|
function unpackMeta(input) {
|
|
641
645
|
const extras = [];
|
|
642
646
|
OpenGraphInputs.forEach((key) => {
|
|
643
|
-
const
|
|
644
|
-
const inputKey =
|
|
647
|
+
const propKey = key.toLowerCase();
|
|
648
|
+
const inputKey = `${key.replace(":", "")}`;
|
|
645
649
|
const val = input[inputKey];
|
|
646
650
|
if (typeof val === "object") {
|
|
647
651
|
(Array.isArray(val) ? val : [val]).forEach((entry) => {
|
|
648
652
|
if (!entry)
|
|
649
653
|
return;
|
|
650
654
|
const unpackedEntry = unpackToArray(entry, {
|
|
651
|
-
key: "property",
|
|
655
|
+
key: key.startsWith("og") ? "property" : "name",
|
|
652
656
|
value: "content",
|
|
653
657
|
resolveKeyData({ key: key2 }) {
|
|
654
|
-
return fixKeyCase(`${
|
|
658
|
+
return fixKeyCase(`${propKey}${key2 !== "url" ? `:${key2}` : ""}`);
|
|
655
659
|
},
|
|
656
660
|
resolveValueData({ value }) {
|
|
657
661
|
return typeof value === "number" ? value.toString() : value;
|
|
658
662
|
}
|
|
659
663
|
});
|
|
660
664
|
extras.push(
|
|
661
|
-
...unpackedEntry.sort((a, b) => a.property ===
|
|
665
|
+
...unpackedEntry.sort((a, b) => a.property === propKey ? -1 : b.property === propKey ? 1 : 0)
|
|
662
666
|
);
|
|
663
667
|
});
|
|
664
668
|
delete input[inputKey];
|
|
665
669
|
}
|
|
666
670
|
});
|
|
667
671
|
SimpleArrayUnpackMetas.forEach((meta2) => {
|
|
668
|
-
if (input[meta2]) {
|
|
672
|
+
if (input[meta2] && typeof input[meta2] !== "string") {
|
|
669
673
|
const val = Array.isArray(input[meta2]) ? input[meta2] : [input[meta2]];
|
|
670
674
|
delete input[meta2];
|
|
671
675
|
val.forEach((entry) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ declare function EventHandlersPlugin(): _unhead_schema.HeadPlugin;
|
|
|
33
33
|
|
|
34
34
|
declare function DedupesTagsPlugin(): _unhead_schema.HeadPlugin;
|
|
35
35
|
|
|
36
|
-
declare function processTemplateParams(s: string,
|
|
36
|
+
declare function processTemplateParams(s: string, p: TemplateParams): string;
|
|
37
37
|
declare function TemplateParamsPlugin(): _unhead_schema.HeadPlugin;
|
|
38
38
|
|
|
39
39
|
declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
package/dist/index.mjs
CHANGED
|
@@ -260,15 +260,17 @@ function DedupesTagsPlugin() {
|
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
function processTemplateParams(s,
|
|
263
|
+
function processTemplateParams(s, p) {
|
|
264
|
+
if (typeof s !== "string")
|
|
265
|
+
return s;
|
|
264
266
|
function sub(token) {
|
|
265
267
|
if (["s", "pageTitle"].includes(token))
|
|
266
|
-
return
|
|
268
|
+
return p.pageTitle;
|
|
267
269
|
let val;
|
|
268
270
|
if (token.includes(".")) {
|
|
269
|
-
val = token.split(".").reduce((acc, key) => acc ? acc[key] || void 0 : void 0,
|
|
271
|
+
val = token.split(".").reduce((acc, key) => acc ? acc[key] || void 0 : void 0, p);
|
|
270
272
|
} else {
|
|
271
|
-
val =
|
|
273
|
+
val = p[token];
|
|
272
274
|
}
|
|
273
275
|
return typeof val !== "undefined" ? val || "" : false;
|
|
274
276
|
}
|
|
@@ -284,12 +286,13 @@ function processTemplateParams(s, config) {
|
|
|
284
286
|
s = s.replace(new RegExp(`\\${token}(\\W|$)`, "g"), `${re}$1`).trim();
|
|
285
287
|
}
|
|
286
288
|
});
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
const sep = p.separator;
|
|
290
|
+
if (s.includes(sep)) {
|
|
291
|
+
if (s.endsWith(sep))
|
|
292
|
+
s = s.slice(0, -sep.length).trim();
|
|
293
|
+
if (s.startsWith(sep))
|
|
294
|
+
s = s.slice(sep.length).trim();
|
|
295
|
+
s = s.replace(new RegExp(`\\${sep}\\s*\\${sep}`, "g"), sep);
|
|
293
296
|
}
|
|
294
297
|
return s;
|
|
295
298
|
}
|
|
@@ -301,7 +304,8 @@ function TemplateParamsPlugin() {
|
|
|
301
304
|
const title = tags.find((tag) => tag.tag === "title")?.textContent;
|
|
302
305
|
const idx = tags.findIndex((tag) => tag.tag === "templateParams");
|
|
303
306
|
const params = idx !== -1 ? tags[idx].props : {};
|
|
304
|
-
params.
|
|
307
|
+
params.separator = params.separator || "|";
|
|
308
|
+
params.pageTitle = processTemplateParams(params.pageTitle || title || "", params);
|
|
305
309
|
for (const tag of tags) {
|
|
306
310
|
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string") {
|
|
307
311
|
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
@@ -607,7 +611,7 @@ function packMeta(inputs) {
|
|
|
607
611
|
});
|
|
608
612
|
}
|
|
609
613
|
|
|
610
|
-
const OpenGraphInputs = ["Image", "Video", "Audio"];
|
|
614
|
+
const OpenGraphInputs = ["og:Image", "og:Video", "og:Audio", "twitter:Image"];
|
|
611
615
|
const SimpleArrayUnpackMetas = ["themeColor"];
|
|
612
616
|
const ColonPrefixKeys = /^(og|twitter|fb)/;
|
|
613
617
|
const PropertyPrefixKeys = /^(og|fb)/;
|
|
@@ -638,32 +642,32 @@ function changeKeyCasingDeep(input) {
|
|
|
638
642
|
function unpackMeta(input) {
|
|
639
643
|
const extras = [];
|
|
640
644
|
OpenGraphInputs.forEach((key) => {
|
|
641
|
-
const
|
|
642
|
-
const inputKey =
|
|
645
|
+
const propKey = key.toLowerCase();
|
|
646
|
+
const inputKey = `${key.replace(":", "")}`;
|
|
643
647
|
const val = input[inputKey];
|
|
644
648
|
if (typeof val === "object") {
|
|
645
649
|
(Array.isArray(val) ? val : [val]).forEach((entry) => {
|
|
646
650
|
if (!entry)
|
|
647
651
|
return;
|
|
648
652
|
const unpackedEntry = unpackToArray(entry, {
|
|
649
|
-
key: "property",
|
|
653
|
+
key: key.startsWith("og") ? "property" : "name",
|
|
650
654
|
value: "content",
|
|
651
655
|
resolveKeyData({ key: key2 }) {
|
|
652
|
-
return fixKeyCase(`${
|
|
656
|
+
return fixKeyCase(`${propKey}${key2 !== "url" ? `:${key2}` : ""}`);
|
|
653
657
|
},
|
|
654
658
|
resolveValueData({ value }) {
|
|
655
659
|
return typeof value === "number" ? value.toString() : value;
|
|
656
660
|
}
|
|
657
661
|
});
|
|
658
662
|
extras.push(
|
|
659
|
-
...unpackedEntry.sort((a, b) => a.property ===
|
|
663
|
+
...unpackedEntry.sort((a, b) => a.property === propKey ? -1 : b.property === propKey ? 1 : 0)
|
|
660
664
|
);
|
|
661
665
|
});
|
|
662
666
|
delete input[inputKey];
|
|
663
667
|
}
|
|
664
668
|
});
|
|
665
669
|
SimpleArrayUnpackMetas.forEach((meta2) => {
|
|
666
|
-
if (input[meta2]) {
|
|
670
|
+
if (input[meta2] && typeof input[meta2] !== "string") {
|
|
667
671
|
const val = Array.isArray(input[meta2]) ? input[meta2] : [input[meta2]];
|
|
668
672
|
delete input[meta2];
|
|
669
673
|
val.forEach((entry) => {
|
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.30",
|
|
5
5
|
"packageManager": "pnpm@8.6.2",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"hookable": "^5.5.3",
|
|
34
|
-
"@unhead/dom": "1.1.
|
|
35
|
-
"@unhead/schema": "1.1.
|
|
36
|
-
"@unhead/shared": "1.1.
|
|
34
|
+
"@unhead/dom": "1.1.30",
|
|
35
|
+
"@unhead/schema": "1.1.30",
|
|
36
|
+
"@unhead/shared": "1.1.30"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"packrup": "^0.1.0"
|