@unhead/addons 1.1.17 → 1.1.19

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