unhead 0.6.9 → 0.7.0
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 +16 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +16 -10
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -17,13 +17,13 @@ const ValidHeadTags = [
|
|
|
17
17
|
];
|
|
18
18
|
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy"];
|
|
19
19
|
|
|
20
|
-
function normaliseTag(tagName, input) {
|
|
20
|
+
async function normaliseTag(tagName, input) {
|
|
21
21
|
const tag = { tag: tagName, props: {} };
|
|
22
22
|
if (tagName === "title" || tagName === "titleTemplate") {
|
|
23
|
-
tag.children = input;
|
|
23
|
+
tag.children = input instanceof Promise ? await input : input;
|
|
24
24
|
return tag;
|
|
25
25
|
}
|
|
26
|
-
tag.props = normaliseProps({ ...input });
|
|
26
|
+
tag.props = await normaliseProps({ ...input });
|
|
27
27
|
["children", "innerHtml", "innerHTML"].forEach((key) => {
|
|
28
28
|
if (typeof tag.props[key] !== "undefined") {
|
|
29
29
|
tag.children = tag.props[key];
|
|
@@ -49,8 +49,11 @@ function normaliseTag(tagName, input) {
|
|
|
49
49
|
}
|
|
50
50
|
return tag;
|
|
51
51
|
}
|
|
52
|
-
function normaliseProps(props) {
|
|
53
|
-
for (const k
|
|
52
|
+
async function normaliseProps(props) {
|
|
53
|
+
for (const k of Object.keys(props)) {
|
|
54
|
+
if (props[k] instanceof Promise) {
|
|
55
|
+
props[k] = await props[k];
|
|
56
|
+
}
|
|
54
57
|
if (String(props[k]) === "true") {
|
|
55
58
|
props[k] = "";
|
|
56
59
|
} else if (String(props[k]) === "false") {
|
|
@@ -561,10 +564,13 @@ const useServerTitleTemplate = (titleTemplate) => useServerHead({ titleTemplate
|
|
|
561
564
|
|
|
562
565
|
const TagEntityBits = 10;
|
|
563
566
|
|
|
564
|
-
function normaliseEntryTags(e) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
567
|
+
async function normaliseEntryTags(e) {
|
|
568
|
+
const tagPromises = [];
|
|
569
|
+
Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).forEach(([k, value]) => {
|
|
570
|
+
const v = asArray(value);
|
|
571
|
+
tagPromises.push(...v.map((props) => normaliseTag(k, props)).flat());
|
|
572
|
+
});
|
|
573
|
+
return (await Promise.all(tagPromises)).flat().map((t, i) => {
|
|
568
574
|
t._e = e._i;
|
|
569
575
|
t._p = (e._i << TagEntityBits) + i;
|
|
570
576
|
return t;
|
|
@@ -647,7 +653,7 @@ function createHeadCore(options = {}) {
|
|
|
647
653
|
const resolveCtx = { tags: [], entries: [...entries] };
|
|
648
654
|
await hooks.callHook("entries:resolve", resolveCtx);
|
|
649
655
|
for (const entry of resolveCtx.entries) {
|
|
650
|
-
for (const tag of normaliseEntryTags(entry)) {
|
|
656
|
+
for (const tag of await normaliseEntryTags(entry)) {
|
|
651
657
|
const tagCtx = { tag, entry };
|
|
652
658
|
await hooks.callHook("tag:normalise", tagCtx);
|
|
653
659
|
resolveCtx.tags.push(tagCtx.tag);
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare const PatchDomOnEntryUpdatesPlugin: (options?: TriggerDomPatchingOnUpdat
|
|
|
27
27
|
*/
|
|
28
28
|
declare const EventHandlersPlugin: () => _unhead_schema.HeadPlugin;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
type Arrayable<T> = T | Array<T>;
|
|
31
31
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
32
32
|
declare const HasElementTags: string[];
|
|
33
33
|
|
|
@@ -75,7 +75,7 @@ declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions
|
|
|
75
75
|
|
|
76
76
|
declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
77
77
|
|
|
78
|
-
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): HeadTag[]
|
|
78
|
+
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
|
|
79
79
|
|
|
80
80
|
declare const composableNames: string[];
|
|
81
81
|
declare const unheadComposablesImports: {
|
package/dist/index.mjs
CHANGED
|
@@ -15,13 +15,13 @@ const ValidHeadTags = [
|
|
|
15
15
|
];
|
|
16
16
|
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy"];
|
|
17
17
|
|
|
18
|
-
function normaliseTag(tagName, input) {
|
|
18
|
+
async function normaliseTag(tagName, input) {
|
|
19
19
|
const tag = { tag: tagName, props: {} };
|
|
20
20
|
if (tagName === "title" || tagName === "titleTemplate") {
|
|
21
|
-
tag.children = input;
|
|
21
|
+
tag.children = input instanceof Promise ? await input : input;
|
|
22
22
|
return tag;
|
|
23
23
|
}
|
|
24
|
-
tag.props = normaliseProps({ ...input });
|
|
24
|
+
tag.props = await normaliseProps({ ...input });
|
|
25
25
|
["children", "innerHtml", "innerHTML"].forEach((key) => {
|
|
26
26
|
if (typeof tag.props[key] !== "undefined") {
|
|
27
27
|
tag.children = tag.props[key];
|
|
@@ -47,8 +47,11 @@ function normaliseTag(tagName, input) {
|
|
|
47
47
|
}
|
|
48
48
|
return tag;
|
|
49
49
|
}
|
|
50
|
-
function normaliseProps(props) {
|
|
51
|
-
for (const k
|
|
50
|
+
async function normaliseProps(props) {
|
|
51
|
+
for (const k of Object.keys(props)) {
|
|
52
|
+
if (props[k] instanceof Promise) {
|
|
53
|
+
props[k] = await props[k];
|
|
54
|
+
}
|
|
52
55
|
if (String(props[k]) === "true") {
|
|
53
56
|
props[k] = "";
|
|
54
57
|
} else if (String(props[k]) === "false") {
|
|
@@ -559,10 +562,13 @@ const useServerTitleTemplate = (titleTemplate) => useServerHead({ titleTemplate
|
|
|
559
562
|
|
|
560
563
|
const TagEntityBits = 10;
|
|
561
564
|
|
|
562
|
-
function normaliseEntryTags(e) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
565
|
+
async function normaliseEntryTags(e) {
|
|
566
|
+
const tagPromises = [];
|
|
567
|
+
Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).forEach(([k, value]) => {
|
|
568
|
+
const v = asArray(value);
|
|
569
|
+
tagPromises.push(...v.map((props) => normaliseTag(k, props)).flat());
|
|
570
|
+
});
|
|
571
|
+
return (await Promise.all(tagPromises)).flat().map((t, i) => {
|
|
566
572
|
t._e = e._i;
|
|
567
573
|
t._p = (e._i << TagEntityBits) + i;
|
|
568
574
|
return t;
|
|
@@ -645,7 +651,7 @@ function createHeadCore(options = {}) {
|
|
|
645
651
|
const resolveCtx = { tags: [], entries: [...entries] };
|
|
646
652
|
await hooks.callHook("entries:resolve", resolveCtx);
|
|
647
653
|
for (const entry of resolveCtx.entries) {
|
|
648
|
-
for (const tag of normaliseEntryTags(entry)) {
|
|
654
|
+
for (const tag of await normaliseEntryTags(entry)) {
|
|
649
655
|
const tagCtx = { tag, entry };
|
|
650
656
|
await hooks.callHook("tag:normalise", tagCtx);
|
|
651
657
|
resolveCtx.tags.push(tagCtx.tag);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/dom": "0.
|
|
34
|
-
"@unhead/schema": "0.
|
|
33
|
+
"@unhead/dom": "0.7.0",
|
|
34
|
+
"@unhead/schema": "0.7.0",
|
|
35
35
|
"hookable": "^5.4.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"zhead": "1.0.
|
|
38
|
+
"zhead": "^1.0.1"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "unbuild .",
|