@fluixi/head 1.0.0-alpha.49 → 1.0.0-alpha.51
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/components.cjs +88 -0
- package/dist/components.mjs +65 -0
- package/dist/core.cjs +297 -0
- package/dist/core.mjs +276 -0
- package/dist/index.cjs +655 -0
- package/dist/index.mjs +638 -0
- package/dist/jsonld.cjs +94 -0
- package/dist/jsonld.mjs +73 -0
- package/dist/reconcile.cjs +309 -0
- package/dist/reconcile.mjs +288 -0
- package/dist/serialize.cjs +292 -0
- package/dist/serialize.mjs +269 -0
- package/dist/sitemap.cjs +115 -0
- package/dist/sitemap.mjs +94 -0
- package/dist/transport.cjs +61 -0
- package/dist/transport.mjs +40 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types.cjs +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +12 -6
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components.ts
|
|
21
|
+
var components_exports = {};
|
|
22
|
+
__export(components_exports, {
|
|
23
|
+
Base: () => Base,
|
|
24
|
+
JsonLD: () => JsonLD,
|
|
25
|
+
Link: () => Link,
|
|
26
|
+
Meta: () => Meta,
|
|
27
|
+
Script: () => Script,
|
|
28
|
+
Title: () => Title
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(components_exports);
|
|
31
|
+
|
|
32
|
+
// src/core.ts
|
|
33
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
34
|
+
var active = null;
|
|
35
|
+
function getActiveHead() {
|
|
36
|
+
return active;
|
|
37
|
+
}
|
|
38
|
+
function useHead(input) {
|
|
39
|
+
const h = getActiveHead();
|
|
40
|
+
if (!h) {
|
|
41
|
+
const proc = globalThis.process;
|
|
42
|
+
if (proc?.env?.NODE_ENV !== "production") {
|
|
43
|
+
console.warn("[fluixi/head] useHead() called with no active head registry — ignored.");
|
|
44
|
+
}
|
|
45
|
+
return () => {
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const dispose = h.push(input);
|
|
49
|
+
if (typeof window !== "undefined" && (0, import_signal.getOwner)()) (0, import_signal.onCleanup)(dispose);
|
|
50
|
+
return dispose;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/components.ts
|
|
54
|
+
function read(v) {
|
|
55
|
+
return typeof v === "function" ? v() : v;
|
|
56
|
+
}
|
|
57
|
+
function Title(props) {
|
|
58
|
+
useHead(() => ({ title: read(props.children) }));
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function Meta(props) {
|
|
62
|
+
useHead(() => ({ meta: [{ ...props, content: read(props.content) }] }));
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
function Link(props) {
|
|
66
|
+
useHead(() => {
|
|
67
|
+
const l = {};
|
|
68
|
+
for (const [k, v] of Object.entries(props)) l[k] = read(v);
|
|
69
|
+
return { link: [l] };
|
|
70
|
+
});
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function Script(props) {
|
|
74
|
+
useHead(() => {
|
|
75
|
+
const s = {};
|
|
76
|
+
for (const [k, v] of Object.entries(props)) s[k] = read(v);
|
|
77
|
+
return { script: [s] };
|
|
78
|
+
});
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function Base(props) {
|
|
82
|
+
useHead({ base: props.href });
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
function JsonLD(props) {
|
|
86
|
+
useHead(() => ({ jsonLd: read(props.data) }));
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/core.ts
|
|
2
|
+
import { getOwner, onCleanup, createSignal } from "@fluixi/reactive/signal";
|
|
3
|
+
var active = null;
|
|
4
|
+
function getActiveHead() {
|
|
5
|
+
return active;
|
|
6
|
+
}
|
|
7
|
+
function useHead(input) {
|
|
8
|
+
const h = getActiveHead();
|
|
9
|
+
if (!h) {
|
|
10
|
+
const proc = globalThis.process;
|
|
11
|
+
if (proc?.env?.NODE_ENV !== "production") {
|
|
12
|
+
console.warn("[fluixi/head] useHead() called with no active head registry — ignored.");
|
|
13
|
+
}
|
|
14
|
+
return () => {
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const dispose = h.push(input);
|
|
18
|
+
if (typeof window !== "undefined" && getOwner()) onCleanup(dispose);
|
|
19
|
+
return dispose;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/components.ts
|
|
23
|
+
function read(v) {
|
|
24
|
+
return typeof v === "function" ? v() : v;
|
|
25
|
+
}
|
|
26
|
+
function Title(props) {
|
|
27
|
+
useHead(() => ({ title: read(props.children) }));
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
function Meta(props) {
|
|
31
|
+
useHead(() => ({ meta: [{ ...props, content: read(props.content) }] }));
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function Link(props) {
|
|
35
|
+
useHead(() => {
|
|
36
|
+
const l = {};
|
|
37
|
+
for (const [k, v] of Object.entries(props)) l[k] = read(v);
|
|
38
|
+
return { link: [l] };
|
|
39
|
+
});
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function Script(props) {
|
|
43
|
+
useHead(() => {
|
|
44
|
+
const s = {};
|
|
45
|
+
for (const [k, v] of Object.entries(props)) s[k] = read(v);
|
|
46
|
+
return { script: [s] };
|
|
47
|
+
});
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function Base(props) {
|
|
51
|
+
useHead({ base: props.href });
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function JsonLD(props) {
|
|
55
|
+
useHead(() => ({ jsonLd: read(props.data) }));
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
Base,
|
|
60
|
+
JsonLD,
|
|
61
|
+
Link,
|
|
62
|
+
Meta,
|
|
63
|
+
Script,
|
|
64
|
+
Title
|
|
65
|
+
};
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core.ts
|
|
21
|
+
var core_exports = {};
|
|
22
|
+
__export(core_exports, {
|
|
23
|
+
createHead: () => createHead,
|
|
24
|
+
getActiveHead: () => getActiveHead,
|
|
25
|
+
resolveHead: () => resolveHead,
|
|
26
|
+
runWithHead: () => runWithHead,
|
|
27
|
+
seo: () => seo,
|
|
28
|
+
setActiveHead: () => setActiveHead,
|
|
29
|
+
useHead: () => useHead
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(core_exports);
|
|
32
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
33
|
+
function val(v) {
|
|
34
|
+
return typeof v === "function" ? v() : v;
|
|
35
|
+
}
|
|
36
|
+
function robotsToString(r) {
|
|
37
|
+
if (typeof r === "string") return r;
|
|
38
|
+
const out = [];
|
|
39
|
+
out.push(r.index === false ? "noindex" : "index");
|
|
40
|
+
out.push(r.follow === false ? "nofollow" : "follow");
|
|
41
|
+
if (r.noarchive) out.push("noarchive");
|
|
42
|
+
if (r.nosnippet) out.push("nosnippet");
|
|
43
|
+
if (r.noimageindex) out.push("noimageindex");
|
|
44
|
+
if (r.maxSnippet != null) out.push(`max-snippet:${r.maxSnippet}`);
|
|
45
|
+
if (r.maxImagePreview) out.push(`max-image-preview:${r.maxImagePreview}`);
|
|
46
|
+
if (r.maxVideoPreview != null) out.push(`max-video-preview:${r.maxVideoPreview}`);
|
|
47
|
+
return out.join(", ");
|
|
48
|
+
}
|
|
49
|
+
function createHead() {
|
|
50
|
+
const sources = [];
|
|
51
|
+
const [version, bump] = (0, import_signal.createSignal)(0);
|
|
52
|
+
return {
|
|
53
|
+
sources,
|
|
54
|
+
version,
|
|
55
|
+
push(input) {
|
|
56
|
+
sources.push(input);
|
|
57
|
+
bump((n) => n + 1);
|
|
58
|
+
return () => {
|
|
59
|
+
const i = sources.indexOf(input);
|
|
60
|
+
if (i !== -1) {
|
|
61
|
+
sources.splice(i, 1);
|
|
62
|
+
bump((n) => n + 1);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
var active = null;
|
|
69
|
+
function setActiveHead(h) {
|
|
70
|
+
active = h;
|
|
71
|
+
}
|
|
72
|
+
function getActiveHead() {
|
|
73
|
+
return active;
|
|
74
|
+
}
|
|
75
|
+
function runWithHead(h, fn) {
|
|
76
|
+
const prev = active;
|
|
77
|
+
active = h;
|
|
78
|
+
try {
|
|
79
|
+
return fn();
|
|
80
|
+
} finally {
|
|
81
|
+
active = prev;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function useHead(input) {
|
|
85
|
+
const h = getActiveHead();
|
|
86
|
+
if (!h) {
|
|
87
|
+
const proc = globalThis.process;
|
|
88
|
+
if (proc?.env?.NODE_ENV !== "production") {
|
|
89
|
+
console.warn("[fluixi/head] useHead() called with no active head registry — ignored.");
|
|
90
|
+
}
|
|
91
|
+
return () => {
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const dispose = h.push(input);
|
|
95
|
+
if (typeof window !== "undefined" && (0, import_signal.getOwner)()) (0, import_signal.onCleanup)(dispose);
|
|
96
|
+
return dispose;
|
|
97
|
+
}
|
|
98
|
+
var seo = useHead;
|
|
99
|
+
function djb2(s) {
|
|
100
|
+
let h = 5381;
|
|
101
|
+
for (let i = 0; i < s.length; i++) h = h * 33 ^ s.charCodeAt(i);
|
|
102
|
+
return (h >>> 0).toString(36);
|
|
103
|
+
}
|
|
104
|
+
function metaKey(a) {
|
|
105
|
+
if (a.charset != null) return "meta:charset";
|
|
106
|
+
if (a.property) return "meta:property:" + a.property;
|
|
107
|
+
if (a.name) return "meta:name:" + a.name;
|
|
108
|
+
if (a["http-equiv"]) return "meta:http-equiv:" + a["http-equiv"];
|
|
109
|
+
return "meta:" + djb2(JSON.stringify(a));
|
|
110
|
+
}
|
|
111
|
+
function pushImage(out, img) {
|
|
112
|
+
const o = typeof img === "string" ? { url: img } : img;
|
|
113
|
+
out.push({ tag: "meta", key: "meta:property:og:image:" + o.url, attrs: { property: "og:image", content: o.url } });
|
|
114
|
+
if (o.secureUrl) out.push({ tag: "meta", key: "meta:property:og:image:secure:" + o.url, attrs: { property: "og:image:secure_url", content: o.secureUrl } });
|
|
115
|
+
if (o.type) out.push({ tag: "meta", key: "meta:property:og:image:type:" + o.url, attrs: { property: "og:image:type", content: o.type } });
|
|
116
|
+
if (o.width != null) out.push({ tag: "meta", key: "meta:property:og:image:width:" + o.url, attrs: { property: "og:image:width", content: String(o.width) } });
|
|
117
|
+
if (o.height != null) out.push({ tag: "meta", key: "meta:property:og:image:height:" + o.url, attrs: { property: "og:image:height", content: String(o.height) } });
|
|
118
|
+
if (o.alt) out.push({ tag: "meta", key: "meta:property:og:image:alt:" + o.url, attrs: { property: "og:image:alt", content: o.alt } });
|
|
119
|
+
}
|
|
120
|
+
function expandOG(og, out) {
|
|
121
|
+
const m = (p, c) => {
|
|
122
|
+
if (c != null) out.push({ tag: "meta", key: "meta:property:og:" + p, attrs: { property: "og:" + p, content: c } });
|
|
123
|
+
};
|
|
124
|
+
m("title", og.title);
|
|
125
|
+
m("description", og.description);
|
|
126
|
+
m("type", og.type);
|
|
127
|
+
m("url", og.url);
|
|
128
|
+
m("site_name", og.siteName);
|
|
129
|
+
m("locale", og.locale);
|
|
130
|
+
for (const l of og.localeAlternate ?? []) out.push({ tag: "meta", key: "meta:property:og:locale:alt:" + l, attrs: { property: "og:locale:alternate", content: l } });
|
|
131
|
+
if (og.image != null) {
|
|
132
|
+
const imgs = Array.isArray(og.image) ? og.image : [og.image];
|
|
133
|
+
for (const i of imgs) pushImage(out, i);
|
|
134
|
+
}
|
|
135
|
+
if (og.video) {
|
|
136
|
+
const v = typeof og.video === "string" ? { url: og.video } : og.video;
|
|
137
|
+
m("video", v.url);
|
|
138
|
+
if ("type" in v && v.type) m("video:type", v.type);
|
|
139
|
+
if ("width" in v && v.width != null) m("video:width", String(v.width));
|
|
140
|
+
if ("height" in v && v.height != null) m("video:height", String(v.height));
|
|
141
|
+
}
|
|
142
|
+
if (og.audio) {
|
|
143
|
+
const a = typeof og.audio === "string" ? { url: og.audio } : og.audio;
|
|
144
|
+
m("audio", a.url);
|
|
145
|
+
if ("type" in a && a.type) m("audio:type", a.type);
|
|
146
|
+
}
|
|
147
|
+
if (og.article) {
|
|
148
|
+
const ar = og.article;
|
|
149
|
+
m("article:published_time", ar.publishedTime);
|
|
150
|
+
m("article:modified_time", ar.modifiedTime);
|
|
151
|
+
m("article:expiration_time", ar.expirationTime);
|
|
152
|
+
m("article:section", ar.section);
|
|
153
|
+
for (const au of [].concat(ar.author ?? [])) out.push({ tag: "meta", key: "meta:property:og:article:author:" + au, attrs: { property: "article:author", content: au } });
|
|
154
|
+
for (const t of [].concat(ar.tag ?? [])) out.push({ tag: "meta", key: "meta:property:og:article:tag:" + t, attrs: { property: "article:tag", content: t } });
|
|
155
|
+
}
|
|
156
|
+
if (og.book) {
|
|
157
|
+
const b = og.book;
|
|
158
|
+
m("book:isbn", b.isbn);
|
|
159
|
+
m("book:release_date", b.releaseDate);
|
|
160
|
+
for (const au of [].concat(b.author ?? [])) out.push({ tag: "meta", key: "meta:property:og:book:author:" + au, attrs: { property: "book:author", content: au } });
|
|
161
|
+
for (const t of [].concat(b.tag ?? [])) out.push({ tag: "meta", key: "meta:property:og:book:tag:" + t, attrs: { property: "book:tag", content: t } });
|
|
162
|
+
}
|
|
163
|
+
if (og.profile) {
|
|
164
|
+
const p = og.profile;
|
|
165
|
+
m("profile:first_name", p.firstName);
|
|
166
|
+
m("profile:last_name", p.lastName);
|
|
167
|
+
m("profile:username", p.username);
|
|
168
|
+
m("profile:gender", p.gender);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function expandTwitter(t, out) {
|
|
172
|
+
const m = (n, c) => {
|
|
173
|
+
if (c != null) out.push({ tag: "meta", key: "meta:name:twitter:" + n, attrs: { name: "twitter:" + n, content: c } });
|
|
174
|
+
};
|
|
175
|
+
m("card", t.card);
|
|
176
|
+
m("site", t.site);
|
|
177
|
+
m("creator", t.creator);
|
|
178
|
+
m("title", t.title);
|
|
179
|
+
m("description", t.description);
|
|
180
|
+
m("image", t.image);
|
|
181
|
+
m("image:alt", t.imageAlt);
|
|
182
|
+
m("player", t.player);
|
|
183
|
+
if (t.playerWidth != null) m("player:width", String(t.playerWidth));
|
|
184
|
+
if (t.playerHeight != null) m("player:height", String(t.playerHeight));
|
|
185
|
+
if (t.app) {
|
|
186
|
+
m("app:name:iphone", t.app.name);
|
|
187
|
+
m("app:id:iphone", t.app.idIphone);
|
|
188
|
+
m("app:id:ipad", t.app.idIpad);
|
|
189
|
+
m("app:id:googleplay", t.app.idGooglePlay);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function expandIcons(icons, out) {
|
|
193
|
+
const link = (key, attrs) => out.push({ tag: "link", key, attrs });
|
|
194
|
+
if (icons.icon != null) {
|
|
195
|
+
const arr = typeof icons.icon === "string" ? [{ url: icons.icon }] : icons.icon;
|
|
196
|
+
for (const i of arr) link("link:icon:" + i.url, { rel: "icon", href: i.url, ...i.type ? { type: i.type } : {}, ...i.sizes ? { sizes: i.sizes } : {} });
|
|
197
|
+
}
|
|
198
|
+
if (icons.apple != null) {
|
|
199
|
+
const arr = typeof icons.apple === "string" ? [{ url: icons.apple }] : icons.apple;
|
|
200
|
+
for (const i of arr) link("link:apple-touch-icon:" + i.url, { rel: "apple-touch-icon", href: i.url, ...i.sizes ? { sizes: i.sizes } : {} });
|
|
201
|
+
}
|
|
202
|
+
if (icons.mask) link("link:mask-icon", { rel: "mask-icon", href: icons.mask.url, ...icons.mask.color ? { color: icons.mask.color } : {} });
|
|
203
|
+
if (icons.shortcut) link("link:shortcut", { rel: "shortcut icon", href: icons.shortcut });
|
|
204
|
+
if (icons.msTileImage) out.push({ tag: "meta", key: "meta:name:msapplication-TileImage", attrs: { name: "msapplication-TileImage", content: icons.msTileImage } });
|
|
205
|
+
if (icons.msTileColor) out.push({ tag: "meta", key: "meta:name:msapplication-TileColor", attrs: { name: "msapplication-TileColor", content: icons.msTileColor } });
|
|
206
|
+
}
|
|
207
|
+
function expand(input, out, ts) {
|
|
208
|
+
const meta = (key, attrs) => out.push({ tag: "meta", key, attrs });
|
|
209
|
+
const title = val(input.title);
|
|
210
|
+
if (title !== void 0) ts.title = title;
|
|
211
|
+
if (input.titleTemplate !== void 0) ts.template = input.titleTemplate;
|
|
212
|
+
const lang = val(input.lang);
|
|
213
|
+
if (lang !== void 0) out.push({ tag: "htmlAttr", key: "html:lang", name: "lang", value: lang });
|
|
214
|
+
if (input.charset !== void 0) meta("meta:charset", { charset: input.charset });
|
|
215
|
+
if (input.viewport !== void 0) meta("meta:name:viewport", { name: "viewport", content: input.viewport });
|
|
216
|
+
const desc = val(input.description);
|
|
217
|
+
if (desc !== void 0) meta("meta:name:description", { name: "description", content: desc });
|
|
218
|
+
const kw = val(input.keywords);
|
|
219
|
+
if (kw !== void 0) meta("meta:name:keywords", { name: "keywords", content: Array.isArray(kw) ? kw.join(", ") : kw });
|
|
220
|
+
if (input.author !== void 0) meta("meta:name:author", { name: "author", content: input.author });
|
|
221
|
+
if (input.robots !== void 0) meta("meta:name:robots", { name: "robots", content: robotsToString(input.robots) });
|
|
222
|
+
if (input.generator !== void 0) meta("meta:name:generator", { name: "generator", content: input.generator });
|
|
223
|
+
if (input.applicationName !== void 0) meta("meta:name:application-name", { name: "application-name", content: input.applicationName });
|
|
224
|
+
if (input.referrer !== void 0) meta("meta:name:referrer", { name: "referrer", content: input.referrer });
|
|
225
|
+
if (input.colorScheme !== void 0) meta("meta:name:color-scheme", { name: "color-scheme", content: input.colorScheme });
|
|
226
|
+
const theme = val(input.themeColor);
|
|
227
|
+
if (theme !== void 0) meta("meta:name:theme-color", { name: "theme-color", content: theme });
|
|
228
|
+
const canonical = val(input.canonical);
|
|
229
|
+
if (canonical !== void 0) out.push({ tag: "link", key: "link:rel:canonical", attrs: { rel: "canonical", href: canonical } });
|
|
230
|
+
if (input.manifest !== void 0) out.push({ tag: "link", key: "link:rel:manifest", attrs: { rel: "manifest", href: input.manifest } });
|
|
231
|
+
if (input.base !== void 0) out.push({ tag: "base", key: "base", attrs: { href: input.base } });
|
|
232
|
+
if (input.verification) {
|
|
233
|
+
const map = { google: "google-site-verification", bing: "msvalidate.01", yandex: "yandex-verification", pinterest: "p:domain_verify" };
|
|
234
|
+
for (const [k, v] of Object.entries(input.verification)) {
|
|
235
|
+
if (v == null) continue;
|
|
236
|
+
const name = map[k] ?? k;
|
|
237
|
+
meta("meta:name:" + name, { name, content: v });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (const a of input.alternates ?? []) out.push({ tag: "link", key: "link:alternate:hreflang:" + a.hreflang, attrs: { rel: "alternate", hreflang: a.hreflang, href: a.href } });
|
|
241
|
+
for (const f of input.feeds ?? []) out.push({ tag: "link", key: "link:alternate:feed:" + f.href, attrs: { rel: "alternate", type: f.type ?? "application/rss+xml", href: f.href, ...f.title ? { title: f.title } : {} } });
|
|
242
|
+
if (input.og) expandOG(input.og, out);
|
|
243
|
+
if (input.twitter) expandTwitter(input.twitter, out);
|
|
244
|
+
if (input.icons) expandIcons(input.icons, out);
|
|
245
|
+
const ld = val(input.jsonLd);
|
|
246
|
+
if (ld !== void 0) {
|
|
247
|
+
const arr = Array.isArray(ld) ? ld : [ld];
|
|
248
|
+
for (const obj of arr) {
|
|
249
|
+
const json = JSON.stringify(obj);
|
|
250
|
+
out.push({ tag: "script", key: "script:ldjson:" + djb2(json), attrs: { type: "application/ld+json" }, children: json });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const m of input.meta ?? []) {
|
|
254
|
+
const attrs = {};
|
|
255
|
+
for (const [k, v] of Object.entries(m)) if (v != null) attrs[k === "httpEquiv" ? "http-equiv" : k] = v;
|
|
256
|
+
out.push({ tag: "meta", key: metaKey(attrs), attrs });
|
|
257
|
+
}
|
|
258
|
+
for (const l of input.link ?? []) {
|
|
259
|
+
const attrs = {};
|
|
260
|
+
for (const [k, v] of Object.entries(l)) if (v != null) attrs[k] = v;
|
|
261
|
+
out.push({ tag: "link", key: "link:" + (attrs.rel ?? "") + ":" + (attrs.href ?? djb2(JSON.stringify(attrs))), attrs });
|
|
262
|
+
}
|
|
263
|
+
for (const s of input.script ?? []) {
|
|
264
|
+
const attrs = {};
|
|
265
|
+
let children;
|
|
266
|
+
for (const [k, v] of Object.entries(s)) {
|
|
267
|
+
if (v == null) continue;
|
|
268
|
+
if (k === "children") children = v;
|
|
269
|
+
else attrs[k] = v;
|
|
270
|
+
}
|
|
271
|
+
out.push({ tag: "script", key: "script:" + (attrs.src ?? djb2((children ?? "") + JSON.stringify(attrs))), attrs, children });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function applyTemplate(tpl, title) {
|
|
275
|
+
return typeof tpl === "function" ? tpl(title) : tpl.includes("%s") ? tpl.replace("%s", title) : tpl;
|
|
276
|
+
}
|
|
277
|
+
function resolveHead(head) {
|
|
278
|
+
const raw = [];
|
|
279
|
+
const ts = {};
|
|
280
|
+
for (const src of head.sources) {
|
|
281
|
+
const input = typeof src === "function" ? src() : src;
|
|
282
|
+
expand(input, raw, ts);
|
|
283
|
+
}
|
|
284
|
+
if (ts.title !== void 0) {
|
|
285
|
+
raw.push({ tag: "title", key: "title", children: ts.template ? applyTemplate(ts.template, ts.title) : ts.title });
|
|
286
|
+
}
|
|
287
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
288
|
+
const htmlAttrs = {};
|
|
289
|
+
for (const t of raw) {
|
|
290
|
+
if (t.tag === "htmlAttr") {
|
|
291
|
+
htmlAttrs[t.name] = t.value;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
byKey.set(t.key, t);
|
|
295
|
+
}
|
|
296
|
+
return { tags: [...byKey.values()], htmlAttrs };
|
|
297
|
+
}
|