@unhead/addons 1.0.11 → 1.0.13
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 +50 -41
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +50 -41
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,54 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
const unhead = require('unhead');
|
|
4
4
|
|
|
5
|
-
const InferSeoMetaPlugin = (options) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
const InferSeoMetaPlugin = (options) => {
|
|
6
|
+
options = options || {};
|
|
7
|
+
const ogTitleTemplate = options.ogTitle || "%s";
|
|
8
|
+
const ogDescriptionTemplate = options.ogDescription || "%s";
|
|
9
|
+
return unhead.defineHeadPlugin({
|
|
10
|
+
hooks: {
|
|
11
|
+
entries: {
|
|
12
|
+
resolve({ entries }) {
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
|
|
15
|
+
const input = entry[inputKey];
|
|
16
|
+
const resolvedMeta = input.meta || [];
|
|
17
|
+
const title = input.title;
|
|
18
|
+
const ogTitle = resolvedMeta.find((meta) => meta.property === "og:title");
|
|
19
|
+
const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
|
|
20
|
+
const ogDescription = resolvedMeta.find((meta) => meta.property === "og:description");
|
|
21
|
+
entry[inputKey].meta = input.meta || [];
|
|
22
|
+
if (title && !ogTitle) {
|
|
23
|
+
entry[inputKey].meta.push({
|
|
24
|
+
property: "og:title",
|
|
25
|
+
content: (typeof ogTitleTemplate === "function" ? ogTitleTemplate(title) : ogTitleTemplate).replace("%s", title)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (description && !ogDescription) {
|
|
29
|
+
const desc = String(description);
|
|
30
|
+
entry[inputKey].meta.push({
|
|
31
|
+
property: "og:description",
|
|
32
|
+
content: (typeof ogDescriptionTemplate === "function" ? ogDescriptionTemplate(desc) : ogDescriptionTemplate).replace("%s", desc)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const metas = [];
|
|
37
|
+
if (options?.robots !== false) {
|
|
38
|
+
metas.push({
|
|
39
|
+
name: "robots",
|
|
40
|
+
content: options?.robots || "max-snippet: -1; max-image-preview: large; max-video-preview: -1"
|
|
21
41
|
});
|
|
22
42
|
}
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
property: "
|
|
26
|
-
content: options?.
|
|
43
|
+
if (options?.twitterCard !== false) {
|
|
44
|
+
metas.push({
|
|
45
|
+
property: "twitter:card",
|
|
46
|
+
content: options?.twitterCard || "summary_large_image"
|
|
27
47
|
});
|
|
28
48
|
}
|
|
49
|
+
const rootEntry = {
|
|
50
|
+
_i: -1,
|
|
51
|
+
_sde: {},
|
|
52
|
+
input: {
|
|
53
|
+
meta: metas
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
entries.unshift(rootEntry);
|
|
29
57
|
}
|
|
30
|
-
const rootEntry = {
|
|
31
|
-
_i: -1,
|
|
32
|
-
_sde: {},
|
|
33
|
-
input: {
|
|
34
|
-
meta: [
|
|
35
|
-
{
|
|
36
|
-
property: "twitter:card",
|
|
37
|
-
content: options?.twitterCard || "summary_large_image",
|
|
38
|
-
tagPriority: "low"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: "robots",
|
|
42
|
-
content: "max-snippet: -1; max-image-preview: large; max-video-preview: -1",
|
|
43
|
-
tagPriority: "low"
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
entries.unshift(rootEntry);
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
53
62
|
|
|
54
63
|
const DefaultCriticalTags = {
|
|
55
64
|
htmlAttrs: {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,25 +6,25 @@ interface InferSeoMetaPluginOptions {
|
|
|
6
6
|
*
|
|
7
7
|
* @param title
|
|
8
8
|
*/
|
|
9
|
-
ogTitle?: (title: string) => string;
|
|
9
|
+
ogTitle?: string | ((title: string) => string);
|
|
10
10
|
/**
|
|
11
11
|
* Transform the og description.
|
|
12
12
|
*
|
|
13
13
|
* @param title
|
|
14
14
|
*/
|
|
15
|
-
ogDescription?: (description: string) => string;
|
|
15
|
+
ogDescription?: string | ((description: string) => string);
|
|
16
16
|
/**
|
|
17
17
|
* Whether robot meta should be infered.
|
|
18
18
|
*
|
|
19
19
|
* @default true
|
|
20
20
|
*/
|
|
21
|
-
robots?:
|
|
21
|
+
robots?: false | string;
|
|
22
22
|
/**
|
|
23
23
|
* The twitter card to use.
|
|
24
24
|
*
|
|
25
25
|
* @default 'summary_large_image'
|
|
26
26
|
*/
|
|
27
|
-
twitterCard?:
|
|
27
|
+
twitterCard?: false | 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
28
28
|
}
|
|
29
29
|
declare const InferSeoMetaPlugin: (options?: InferSeoMetaPluginOptions) => _unhead_schema.HeadPlugin;
|
|
30
30
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,53 +1,62 @@
|
|
|
1
1
|
import { defineHeadPlugin } from 'unhead';
|
|
2
2
|
|
|
3
|
-
const InferSeoMetaPlugin = (options) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
const InferSeoMetaPlugin = (options) => {
|
|
4
|
+
options = options || {};
|
|
5
|
+
const ogTitleTemplate = options.ogTitle || "%s";
|
|
6
|
+
const ogDescriptionTemplate = options.ogDescription || "%s";
|
|
7
|
+
return defineHeadPlugin({
|
|
8
|
+
hooks: {
|
|
9
|
+
entries: {
|
|
10
|
+
resolve({ entries }) {
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
|
|
13
|
+
const input = entry[inputKey];
|
|
14
|
+
const resolvedMeta = input.meta || [];
|
|
15
|
+
const title = input.title;
|
|
16
|
+
const ogTitle = resolvedMeta.find((meta) => meta.property === "og:title");
|
|
17
|
+
const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
|
|
18
|
+
const ogDescription = resolvedMeta.find((meta) => meta.property === "og:description");
|
|
19
|
+
entry[inputKey].meta = input.meta || [];
|
|
20
|
+
if (title && !ogTitle) {
|
|
21
|
+
entry[inputKey].meta.push({
|
|
22
|
+
property: "og:title",
|
|
23
|
+
content: (typeof ogTitleTemplate === "function" ? ogTitleTemplate(title) : ogTitleTemplate).replace("%s", title)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (description && !ogDescription) {
|
|
27
|
+
const desc = String(description);
|
|
28
|
+
entry[inputKey].meta.push({
|
|
29
|
+
property: "og:description",
|
|
30
|
+
content: (typeof ogDescriptionTemplate === "function" ? ogDescriptionTemplate(desc) : ogDescriptionTemplate).replace("%s", desc)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const metas = [];
|
|
35
|
+
if (options?.robots !== false) {
|
|
36
|
+
metas.push({
|
|
37
|
+
name: "robots",
|
|
38
|
+
content: options?.robots || "max-snippet: -1; max-image-preview: large; max-video-preview: -1"
|
|
19
39
|
});
|
|
20
40
|
}
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
property: "
|
|
24
|
-
content: options?.
|
|
41
|
+
if (options?.twitterCard !== false) {
|
|
42
|
+
metas.push({
|
|
43
|
+
property: "twitter:card",
|
|
44
|
+
content: options?.twitterCard || "summary_large_image"
|
|
25
45
|
});
|
|
26
46
|
}
|
|
47
|
+
const rootEntry = {
|
|
48
|
+
_i: -1,
|
|
49
|
+
_sde: {},
|
|
50
|
+
input: {
|
|
51
|
+
meta: metas
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
entries.unshift(rootEntry);
|
|
27
55
|
}
|
|
28
|
-
const rootEntry = {
|
|
29
|
-
_i: -1,
|
|
30
|
-
_sde: {},
|
|
31
|
-
input: {
|
|
32
|
-
meta: [
|
|
33
|
-
{
|
|
34
|
-
property: "twitter:card",
|
|
35
|
-
content: options?.twitterCard || "summary_large_image",
|
|
36
|
-
tagPriority: "low"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "robots",
|
|
40
|
-
content: "max-snippet: -1; max-image-preview: large; max-video-preview: -1",
|
|
41
|
-
tagPriority: "low"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
entries.unshift(rootEntry);
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
51
60
|
|
|
52
61
|
const DefaultCriticalTags = {
|
|
53
62
|
htmlAttrs: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/addons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.13",
|
|
5
5
|
"packageManager": "pnpm@7.18.1",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"@rollup/pluginutils": "^5.0.2",
|
|
54
54
|
"unplugin": "^1.0.0",
|
|
55
55
|
"unplugin-ast": "^0.5.8",
|
|
56
|
-
"@unhead/schema": "1.0.
|
|
57
|
-
"unhead": "1.0.
|
|
56
|
+
"@unhead/schema": "1.0.13",
|
|
57
|
+
"unhead": "1.0.13"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@babel/types": "^7.20.5",
|