unhead 1.3.8 → 1.4.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 +12 -7
- package/dist/index.d.cts +40 -0
- package/dist/index.d.mts +40 -0
- package/dist/index.mjs +12 -7
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -186,17 +186,18 @@ const TemplateParamsPlugin = shared.defineHeadPlugin({
|
|
|
186
186
|
const title = tags.find((tag) => tag.tag === "title")?.textContent;
|
|
187
187
|
const idx = tags.findIndex((tag) => tag.tag === "templateParams");
|
|
188
188
|
const params = idx !== -1 ? tags[idx].props : {};
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const sep = params.separator || "|";
|
|
190
|
+
delete params.separator;
|
|
191
|
+
params.pageTitle = shared.processTemplateParams(params.pageTitle || title || "", params, sep);
|
|
191
192
|
for (const tag of tags) {
|
|
192
193
|
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string")
|
|
193
|
-
tag.textContent = shared.processTemplateParams(tag.textContent, params);
|
|
194
|
+
tag.textContent = shared.processTemplateParams(tag.textContent, params, sep);
|
|
194
195
|
else if (tag.tag === "meta" && typeof tag.props.content === "string")
|
|
195
|
-
tag.props.content = shared.processTemplateParams(tag.props.content, params);
|
|
196
|
+
tag.props.content = shared.processTemplateParams(tag.props.content, params, sep);
|
|
196
197
|
else if (tag.tag === "link" && typeof tag.props.href === "string")
|
|
197
|
-
tag.props.href = shared.processTemplateParams(tag.props.href, params);
|
|
198
|
+
tag.props.href = shared.processTemplateParams(tag.props.href, params, sep);
|
|
198
199
|
else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && tag.innerHTML)
|
|
199
|
-
tag.innerHTML = shared.processTemplateParams(tag.innerHTML, params);
|
|
200
|
+
tag.innerHTML = shared.processTemplateParams(tag.innerHTML, params, sep);
|
|
200
201
|
}
|
|
201
202
|
ctx.tags = tags.filter((tag) => tag.tag !== "templateParams");
|
|
202
203
|
}
|
|
@@ -238,11 +239,13 @@ const TitleTemplatePlugin = shared.defineHeadPlugin({
|
|
|
238
239
|
});
|
|
239
240
|
|
|
240
241
|
let activeHead;
|
|
242
|
+
// @__NO_SIDE_EFFECTS__
|
|
241
243
|
function createHead(options = {}) {
|
|
242
244
|
const head = createHeadCore(options);
|
|
243
245
|
head.use(dom.DomPlugin());
|
|
244
246
|
return activeHead = head;
|
|
245
247
|
}
|
|
248
|
+
// @__NO_SIDE_EFFECTS__
|
|
246
249
|
function createServerHead(options = {}) {
|
|
247
250
|
return activeHead = createHeadCore(options);
|
|
248
251
|
}
|
|
@@ -330,6 +333,7 @@ function createHeadCore(options = {}) {
|
|
|
330
333
|
return head;
|
|
331
334
|
}
|
|
332
335
|
|
|
336
|
+
// @__NO_SIDE_EFFECTS__
|
|
333
337
|
function HashHydrationPlugin() {
|
|
334
338
|
let prevHash = false;
|
|
335
339
|
let dirty = false;
|
|
@@ -365,6 +369,7 @@ function HashHydrationPlugin() {
|
|
|
365
369
|
}
|
|
366
370
|
|
|
367
371
|
const importRe = /@import/;
|
|
372
|
+
// @__NO_SIDE_EFFECTS__
|
|
368
373
|
function CapoPlugin(options) {
|
|
369
374
|
return shared.defineHeadPlugin({
|
|
370
375
|
hooks: {
|
|
@@ -372,7 +377,7 @@ function CapoPlugin(options) {
|
|
|
372
377
|
for (const tag of tags) {
|
|
373
378
|
if (tag.tagPriority || tag.tagPosition && tag.tagPosition !== "head")
|
|
374
379
|
continue;
|
|
375
|
-
const isTruthy = (val) => val === "";
|
|
380
|
+
const isTruthy = (val) => val === "" || val === true;
|
|
376
381
|
const isScript = tag.tag === "script";
|
|
377
382
|
const isLink = tag.tag === "link";
|
|
378
383
|
if (isScript && isTruthy(tag.props.async)) {
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as _unhead_schema from '@unhead/schema';
|
|
2
|
+
import { Head, CreateHeadOptions, Unhead, HeadEntryOptions, ActiveHeadEntry, HeadSafe, UseSeoMetaInput } from '@unhead/schema';
|
|
3
|
+
export { composableNames } from '@unhead/shared';
|
|
4
|
+
|
|
5
|
+
declare function createHead<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
6
|
+
declare function createServerHead<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
|
9
|
+
* and does not register DOM plugins.
|
|
10
|
+
*
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
14
|
+
|
|
15
|
+
declare function HashHydrationPlugin(): _unhead_schema.HeadPlugin;
|
|
16
|
+
|
|
17
|
+
declare function CapoPlugin(options: {
|
|
18
|
+
track?: boolean;
|
|
19
|
+
}): _unhead_schema.HeadPlugin;
|
|
20
|
+
|
|
21
|
+
declare const unheadComposablesImports: {
|
|
22
|
+
from: string;
|
|
23
|
+
imports: string[];
|
|
24
|
+
}[];
|
|
25
|
+
|
|
26
|
+
declare function getActiveHead(): _unhead_schema.Unhead<any> | undefined;
|
|
27
|
+
|
|
28
|
+
declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
29
|
+
|
|
30
|
+
declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe> | void;
|
|
31
|
+
|
|
32
|
+
declare function useServerHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
33
|
+
|
|
34
|
+
declare function useServerHeadSafe<T extends HeadSafe>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
35
|
+
|
|
36
|
+
declare function useSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
|
|
37
|
+
|
|
38
|
+
declare function useServerSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
|
|
39
|
+
|
|
40
|
+
export { CapoPlugin, HashHydrationPlugin, createHead, createHeadCore, createServerHead, getActiveHead, unheadComposablesImports, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as _unhead_schema from '@unhead/schema';
|
|
2
|
+
import { Head, CreateHeadOptions, Unhead, HeadEntryOptions, ActiveHeadEntry, HeadSafe, UseSeoMetaInput } from '@unhead/schema';
|
|
3
|
+
export { composableNames } from '@unhead/shared';
|
|
4
|
+
|
|
5
|
+
declare function createHead<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
6
|
+
declare function createServerHead<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
|
9
|
+
* and does not register DOM plugins.
|
|
10
|
+
*
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
14
|
+
|
|
15
|
+
declare function HashHydrationPlugin(): _unhead_schema.HeadPlugin;
|
|
16
|
+
|
|
17
|
+
declare function CapoPlugin(options: {
|
|
18
|
+
track?: boolean;
|
|
19
|
+
}): _unhead_schema.HeadPlugin;
|
|
20
|
+
|
|
21
|
+
declare const unheadComposablesImports: {
|
|
22
|
+
from: string;
|
|
23
|
+
imports: string[];
|
|
24
|
+
}[];
|
|
25
|
+
|
|
26
|
+
declare function getActiveHead(): _unhead_schema.Unhead<any> | undefined;
|
|
27
|
+
|
|
28
|
+
declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
29
|
+
|
|
30
|
+
declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe> | void;
|
|
31
|
+
|
|
32
|
+
declare function useServerHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
33
|
+
|
|
34
|
+
declare function useServerHeadSafe<T extends HeadSafe>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
35
|
+
|
|
36
|
+
declare function useSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
|
|
37
|
+
|
|
38
|
+
declare function useServerSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
|
|
39
|
+
|
|
40
|
+
export { CapoPlugin, HashHydrationPlugin, createHead, createHeadCore, createServerHead, getActiveHead, unheadComposablesImports, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
|
package/dist/index.mjs
CHANGED
|
@@ -185,17 +185,18 @@ const TemplateParamsPlugin = defineHeadPlugin({
|
|
|
185
185
|
const title = tags.find((tag) => tag.tag === "title")?.textContent;
|
|
186
186
|
const idx = tags.findIndex((tag) => tag.tag === "templateParams");
|
|
187
187
|
const params = idx !== -1 ? tags[idx].props : {};
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
const sep = params.separator || "|";
|
|
189
|
+
delete params.separator;
|
|
190
|
+
params.pageTitle = processTemplateParams(params.pageTitle || title || "", params, sep);
|
|
190
191
|
for (const tag of tags) {
|
|
191
192
|
if (["titleTemplate", "title"].includes(tag.tag) && typeof tag.textContent === "string")
|
|
192
|
-
tag.textContent = processTemplateParams(tag.textContent, params);
|
|
193
|
+
tag.textContent = processTemplateParams(tag.textContent, params, sep);
|
|
193
194
|
else if (tag.tag === "meta" && typeof tag.props.content === "string")
|
|
194
|
-
tag.props.content = processTemplateParams(tag.props.content, params);
|
|
195
|
+
tag.props.content = processTemplateParams(tag.props.content, params, sep);
|
|
195
196
|
else if (tag.tag === "link" && typeof tag.props.href === "string")
|
|
196
|
-
tag.props.href = processTemplateParams(tag.props.href, params);
|
|
197
|
+
tag.props.href = processTemplateParams(tag.props.href, params, sep);
|
|
197
198
|
else if (tag.tag === "script" && ["application/json", "application/ld+json"].includes(tag.props.type) && tag.innerHTML)
|
|
198
|
-
tag.innerHTML = processTemplateParams(tag.innerHTML, params);
|
|
199
|
+
tag.innerHTML = processTemplateParams(tag.innerHTML, params, sep);
|
|
199
200
|
}
|
|
200
201
|
ctx.tags = tags.filter((tag) => tag.tag !== "templateParams");
|
|
201
202
|
}
|
|
@@ -237,11 +238,13 @@ const TitleTemplatePlugin = defineHeadPlugin({
|
|
|
237
238
|
});
|
|
238
239
|
|
|
239
240
|
let activeHead;
|
|
241
|
+
// @__NO_SIDE_EFFECTS__
|
|
240
242
|
function createHead(options = {}) {
|
|
241
243
|
const head = createHeadCore(options);
|
|
242
244
|
head.use(DomPlugin());
|
|
243
245
|
return activeHead = head;
|
|
244
246
|
}
|
|
247
|
+
// @__NO_SIDE_EFFECTS__
|
|
245
248
|
function createServerHead(options = {}) {
|
|
246
249
|
return activeHead = createHeadCore(options);
|
|
247
250
|
}
|
|
@@ -329,6 +332,7 @@ function createHeadCore(options = {}) {
|
|
|
329
332
|
return head;
|
|
330
333
|
}
|
|
331
334
|
|
|
335
|
+
// @__NO_SIDE_EFFECTS__
|
|
332
336
|
function HashHydrationPlugin() {
|
|
333
337
|
let prevHash = false;
|
|
334
338
|
let dirty = false;
|
|
@@ -364,6 +368,7 @@ function HashHydrationPlugin() {
|
|
|
364
368
|
}
|
|
365
369
|
|
|
366
370
|
const importRe = /@import/;
|
|
371
|
+
// @__NO_SIDE_EFFECTS__
|
|
367
372
|
function CapoPlugin(options) {
|
|
368
373
|
return defineHeadPlugin({
|
|
369
374
|
hooks: {
|
|
@@ -371,7 +376,7 @@ function CapoPlugin(options) {
|
|
|
371
376
|
for (const tag of tags) {
|
|
372
377
|
if (tag.tagPriority || tag.tagPosition && tag.tagPosition !== "head")
|
|
373
378
|
continue;
|
|
374
|
-
const isTruthy = (val) => val === "";
|
|
379
|
+
const isTruthy = (val) => val === "" || val === true;
|
|
375
380
|
const isScript = tag.tag === "script";
|
|
376
381
|
const isLink = tag.tag === "link";
|
|
377
382
|
if (isScript && isTruthy(tag.props.async)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"hookable": "^5.5.3",
|
|
33
|
-
"@unhead/dom": "1.
|
|
34
|
-
"@unhead/schema": "1.
|
|
35
|
-
"@unhead/shared": "1.
|
|
33
|
+
"@unhead/dom": "1.4.0",
|
|
34
|
+
"@unhead/schema": "1.4.0",
|
|
35
|
+
"@unhead/shared": "1.4.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "unbuild .",
|