unhead 1.1.19 → 1.1.21
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 +14 -14
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +16 -15
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -50,13 +50,6 @@ function SortTagsPlugin() {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const renderTitleTemplate = (template, title) => {
|
|
54
|
-
if (template == null)
|
|
55
|
-
return title || null;
|
|
56
|
-
if (typeof template === "function")
|
|
57
|
-
return template(title);
|
|
58
|
-
return template.replace("%s", title ?? "");
|
|
59
|
-
};
|
|
60
53
|
const TitleTemplatePlugin = () => {
|
|
61
54
|
return shared.defineHeadPlugin({
|
|
62
55
|
hooks: {
|
|
@@ -65,7 +58,7 @@ const TitleTemplatePlugin = () => {
|
|
|
65
58
|
let titleTemplateIdx = tags.findIndex((i) => i.tag === "titleTemplate");
|
|
66
59
|
const titleIdx = tags.findIndex((i) => i.tag === "title");
|
|
67
60
|
if (titleIdx !== -1 && titleTemplateIdx !== -1) {
|
|
68
|
-
const newTitle =
|
|
61
|
+
const newTitle = shared.resolveTitleTemplate(
|
|
69
62
|
tags[titleTemplateIdx].textContent,
|
|
70
63
|
tags[titleIdx].textContent
|
|
71
64
|
);
|
|
@@ -75,7 +68,7 @@ const TitleTemplatePlugin = () => {
|
|
|
75
68
|
delete tags[titleIdx];
|
|
76
69
|
}
|
|
77
70
|
} else if (titleTemplateIdx !== -1) {
|
|
78
|
-
const newTitle =
|
|
71
|
+
const newTitle = shared.resolveTitleTemplate(
|
|
79
72
|
tags[titleTemplateIdx].textContent
|
|
80
73
|
);
|
|
81
74
|
if (newTitle !== null) {
|
|
@@ -308,12 +301,20 @@ function TemplateParamsPlugin() {
|
|
|
308
301
|
const params = idx !== -1 ? tags[idx].textContent : {};
|
|
309
302
|
params.pageTitle = params.pageTitle || title || "";
|
|
310
303
|
for (const tag of tags) {
|
|
311
|
-
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string")
|
|
304
|
+
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string") {
|
|
312
305
|
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
313
|
-
else if (tag.tag === "meta" && typeof tag.props.content === "string")
|
|
306
|
+
} else if (tag.tag === "meta" && typeof tag.props.content === "string") {
|
|
314
307
|
tag.props.content = processTemplateParams(tag.props.content, params);
|
|
315
|
-
else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && typeof tag.innerHTML === "string")
|
|
316
|
-
|
|
308
|
+
} else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && typeof tag.innerHTML === "string") {
|
|
309
|
+
try {
|
|
310
|
+
tag.innerHTML = JSON.stringify(JSON.parse(tag.innerHTML), (key, val) => {
|
|
311
|
+
if (typeof val === "string")
|
|
312
|
+
return processTemplateParams(val, params);
|
|
313
|
+
return val;
|
|
314
|
+
});
|
|
315
|
+
} catch {
|
|
316
|
+
}
|
|
317
|
+
}
|
|
317
318
|
}
|
|
318
319
|
ctx.tags = tags.filter((tag) => tag.tag !== "templateParams");
|
|
319
320
|
}
|
|
@@ -1012,7 +1013,6 @@ exports.normaliseEntryTags = normaliseEntryTags;
|
|
|
1012
1013
|
exports.normaliseProps = normaliseProps;
|
|
1013
1014
|
exports.normaliseTag = normaliseTag;
|
|
1014
1015
|
exports.packMeta = packMeta;
|
|
1015
|
-
exports.renderTitleTemplate = renderTitleTemplate;
|
|
1016
1016
|
exports.resolveMetaKeyType = resolveMetaKeyType;
|
|
1017
1017
|
exports.resolveMetaKeyValue = resolveMetaKeyValue;
|
|
1018
1018
|
exports.resolvePackedMetaObjectValue = resolvePackedMetaObjectValue;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ declare const SortModifiers: {
|
|
|
17
17
|
}[];
|
|
18
18
|
declare function SortTagsPlugin(): _unhead_schema.HeadPlugin;
|
|
19
19
|
|
|
20
|
-
declare const renderTitleTemplate: (template: string | ((title?: string) => string | null) | null, title?: string) => string | null;
|
|
21
20
|
declare const TitleTemplatePlugin: () => _unhead_schema.HeadPlugin;
|
|
22
21
|
|
|
23
22
|
declare const DeprecatedTagAttrPlugin: () => _unhead_schema.HeadPlugin;
|
|
@@ -188,4 +187,4 @@ declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promi
|
|
|
188
187
|
|
|
189
188
|
declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
|
|
190
189
|
|
|
191
|
-
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta,
|
|
190
|
+
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHooks } from 'hookable';
|
|
2
2
|
import { PatchDomOnEntryUpdatesPlugin, maybeGetSSRHash } from '@unhead/dom';
|
|
3
|
-
import { defineHeadPlugin, hashTag, HasElementTags, tagDedupeKey, asArray as asArray$1, hashCode, TagConfigKeys, TagsWithInnerContent, ValidHeadTags } from '@unhead/shared';
|
|
3
|
+
import { defineHeadPlugin, resolveTitleTemplate, hashTag, HasElementTags, tagDedupeKey, asArray as asArray$1, hashCode, TagConfigKeys, TagsWithInnerContent, ValidHeadTags } from '@unhead/shared';
|
|
4
4
|
|
|
5
5
|
const TAG_WEIGHTS = {
|
|
6
6
|
// aliases
|
|
@@ -48,13 +48,6 @@ function SortTagsPlugin() {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const renderTitleTemplate = (template, title) => {
|
|
52
|
-
if (template == null)
|
|
53
|
-
return title || null;
|
|
54
|
-
if (typeof template === "function")
|
|
55
|
-
return template(title);
|
|
56
|
-
return template.replace("%s", title ?? "");
|
|
57
|
-
};
|
|
58
51
|
const TitleTemplatePlugin = () => {
|
|
59
52
|
return defineHeadPlugin({
|
|
60
53
|
hooks: {
|
|
@@ -63,7 +56,7 @@ const TitleTemplatePlugin = () => {
|
|
|
63
56
|
let titleTemplateIdx = tags.findIndex((i) => i.tag === "titleTemplate");
|
|
64
57
|
const titleIdx = tags.findIndex((i) => i.tag === "title");
|
|
65
58
|
if (titleIdx !== -1 && titleTemplateIdx !== -1) {
|
|
66
|
-
const newTitle =
|
|
59
|
+
const newTitle = resolveTitleTemplate(
|
|
67
60
|
tags[titleTemplateIdx].textContent,
|
|
68
61
|
tags[titleIdx].textContent
|
|
69
62
|
);
|
|
@@ -73,7 +66,7 @@ const TitleTemplatePlugin = () => {
|
|
|
73
66
|
delete tags[titleIdx];
|
|
74
67
|
}
|
|
75
68
|
} else if (titleTemplateIdx !== -1) {
|
|
76
|
-
const newTitle =
|
|
69
|
+
const newTitle = resolveTitleTemplate(
|
|
77
70
|
tags[titleTemplateIdx].textContent
|
|
78
71
|
);
|
|
79
72
|
if (newTitle !== null) {
|
|
@@ -306,12 +299,20 @@ function TemplateParamsPlugin() {
|
|
|
306
299
|
const params = idx !== -1 ? tags[idx].textContent : {};
|
|
307
300
|
params.pageTitle = params.pageTitle || title || "";
|
|
308
301
|
for (const tag of tags) {
|
|
309
|
-
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string")
|
|
302
|
+
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string") {
|
|
310
303
|
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
311
|
-
else if (tag.tag === "meta" && typeof tag.props.content === "string")
|
|
304
|
+
} else if (tag.tag === "meta" && typeof tag.props.content === "string") {
|
|
312
305
|
tag.props.content = processTemplateParams(tag.props.content, params);
|
|
313
|
-
else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && typeof tag.innerHTML === "string")
|
|
314
|
-
|
|
306
|
+
} else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && typeof tag.innerHTML === "string") {
|
|
307
|
+
try {
|
|
308
|
+
tag.innerHTML = JSON.stringify(JSON.parse(tag.innerHTML), (key, val) => {
|
|
309
|
+
if (typeof val === "string")
|
|
310
|
+
return processTemplateParams(val, params);
|
|
311
|
+
return val;
|
|
312
|
+
});
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
}
|
|
315
316
|
}
|
|
316
317
|
ctx.tags = tags.filter((tag) => tag.tag !== "templateParams");
|
|
317
318
|
}
|
|
@@ -988,4 +989,4 @@ const unheadComposablesImports = [
|
|
|
988
989
|
}
|
|
989
990
|
];
|
|
990
991
|
|
|
991
|
-
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta,
|
|
992
|
+
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
|
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.21",
|
|
5
5
|
"packageManager": "pnpm@7.28.0",
|
|
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.4.2",
|
|
34
|
-
"@unhead/dom": "1.1.
|
|
35
|
-
"@unhead/schema": "1.1.
|
|
36
|
-
"@unhead/shared": "1.1.
|
|
34
|
+
"@unhead/dom": "1.1.21",
|
|
35
|
+
"@unhead/schema": "1.1.21",
|
|
36
|
+
"@unhead/shared": "1.1.21"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"packrup": "^0.1.0"
|