@unhead/addons 1.0.10 → 1.0.11

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 CHANGED
@@ -4,54 +4,48 @@ const unhead = require('unhead');
4
4
 
5
5
  const InferSeoMetaPlugin = (options) => unhead.defineHeadPlugin({
6
6
  hooks: {
7
- tags: {
8
- resolve(ctx) {
9
- const tags = ctx.tags.reverse();
10
- const title = tags.find((t) => t.tag === "title" && !!t.children);
11
- const ogTitle = tags.find((t) => t.tag === "meta" && t.props.property === "og:title" && t._e === title?._e);
12
- if (title && !ogTitle) {
13
- ctx.tags.push({
14
- _e: title._e,
15
- tag: "meta",
16
- props: {
7
+ entries: {
8
+ resolve({ entries }) {
9
+ for (const entry of entries) {
10
+ const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
11
+ const input = entry[inputKey];
12
+ const resolvedMeta = input.meta || [];
13
+ const title = input.title;
14
+ const ogTitle = resolvedMeta.find((meta) => meta.property === "og:title");
15
+ const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
16
+ const ogDescription = resolvedMeta.find((meta) => meta.property === "og:description");
17
+ if (title && !ogTitle) {
18
+ entry[inputKey].meta.push({
17
19
  property: "og:title",
18
- content: options?.ogTitle ? options.ogTitle(title.children) : title.children
19
- }
20
- });
21
- }
22
- const description = ctx.tags.find((t) => t.tag === "meta" && t.props.name === "description" && !!t.props.content);
23
- const ogDescription = tags.find((t) => t.tag === "meta" && t.props.property === "og:description" && t._e === description?._e);
24
- if (description && !ogDescription) {
25
- ctx.tags.push({
26
- _e: description._e,
27
- tag: "meta",
28
- props: {
29
- name: "og:description",
30
- content: options?.ogDescription ? options.ogDescription(description.props.content) : description.props.content
31
- }
32
- });
33
- }
34
- const ogImage = ctx.tags.find((t) => t.tag === "meta" && t.props.property === "og:image");
35
- if (ogImage && !ctx.tags.find((t) => t.tag === "meta" && t.props.property === "twitter:card")) {
36
- ctx.tags.push({
37
- _e: ogImage._e,
38
- tag: "meta",
39
- props: {
40
- property: "twitter:card",
41
- content: options?.twitterCard || "summary_large_image"
42
- }
43
- });
44
- }
45
- if (options?.robots !== false && !ctx.tags.find((t) => t.tag === "meta" && t.props.name === "robots")) {
46
- ctx.tags.push({
47
- _e: ctx.tags[0]._e,
48
- tag: "meta",
49
- props: {
50
- name: "robots",
51
- content: "max-snippet: -1; max-image-preview: large; max-video-preview: -1"
52
- }
53
- });
20
+ content: options?.ogTitle ? options.ogTitle(title) : title
21
+ });
22
+ }
23
+ if (description && !ogDescription) {
24
+ entry[inputKey].meta.push({
25
+ property: "og:description",
26
+ content: options?.ogDescription ? options.ogDescription(String(description)) : description
27
+ });
28
+ }
54
29
  }
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);
55
49
  }
56
50
  }
57
51
  }
package/dist/index.mjs CHANGED
@@ -2,54 +2,48 @@ import { defineHeadPlugin } from 'unhead';
2
2
 
3
3
  const InferSeoMetaPlugin = (options) => defineHeadPlugin({
4
4
  hooks: {
5
- tags: {
6
- resolve(ctx) {
7
- const tags = ctx.tags.reverse();
8
- const title = tags.find((t) => t.tag === "title" && !!t.children);
9
- const ogTitle = tags.find((t) => t.tag === "meta" && t.props.property === "og:title" && t._e === title?._e);
10
- if (title && !ogTitle) {
11
- ctx.tags.push({
12
- _e: title._e,
13
- tag: "meta",
14
- props: {
5
+ entries: {
6
+ resolve({ entries }) {
7
+ for (const entry of entries) {
8
+ const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
9
+ const input = entry[inputKey];
10
+ const resolvedMeta = input.meta || [];
11
+ const title = input.title;
12
+ const ogTitle = resolvedMeta.find((meta) => meta.property === "og:title");
13
+ const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
14
+ const ogDescription = resolvedMeta.find((meta) => meta.property === "og:description");
15
+ if (title && !ogTitle) {
16
+ entry[inputKey].meta.push({
15
17
  property: "og:title",
16
- content: options?.ogTitle ? options.ogTitle(title.children) : title.children
17
- }
18
- });
19
- }
20
- const description = ctx.tags.find((t) => t.tag === "meta" && t.props.name === "description" && !!t.props.content);
21
- const ogDescription = tags.find((t) => t.tag === "meta" && t.props.property === "og:description" && t._e === description?._e);
22
- if (description && !ogDescription) {
23
- ctx.tags.push({
24
- _e: description._e,
25
- tag: "meta",
26
- props: {
27
- name: "og:description",
28
- content: options?.ogDescription ? options.ogDescription(description.props.content) : description.props.content
29
- }
30
- });
31
- }
32
- const ogImage = ctx.tags.find((t) => t.tag === "meta" && t.props.property === "og:image");
33
- if (ogImage && !ctx.tags.find((t) => t.tag === "meta" && t.props.property === "twitter:card")) {
34
- ctx.tags.push({
35
- _e: ogImage._e,
36
- tag: "meta",
37
- props: {
38
- property: "twitter:card",
39
- content: options?.twitterCard || "summary_large_image"
40
- }
41
- });
42
- }
43
- if (options?.robots !== false && !ctx.tags.find((t) => t.tag === "meta" && t.props.name === "robots")) {
44
- ctx.tags.push({
45
- _e: ctx.tags[0]._e,
46
- tag: "meta",
47
- props: {
48
- name: "robots",
49
- content: "max-snippet: -1; max-image-preview: large; max-video-preview: -1"
50
- }
51
- });
18
+ content: options?.ogTitle ? options.ogTitle(title) : title
19
+ });
20
+ }
21
+ if (description && !ogDescription) {
22
+ entry[inputKey].meta.push({
23
+ property: "og:description",
24
+ content: options?.ogDescription ? options.ogDescription(String(description)) : description
25
+ });
26
+ }
52
27
  }
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);
53
47
  }
54
48
  }
55
49
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/addons",
3
3
  "type": "module",
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
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.10",
57
- "unhead": "1.0.10"
56
+ "@unhead/schema": "1.0.11",
57
+ "unhead": "1.0.11"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@babel/types": "^7.20.5",