@unhead/addons 1.1.19 → 1.1.20

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
@@ -2,16 +2,23 @@
2
2
 
3
3
  const shared = require('@unhead/shared');
4
4
 
5
- const InferSeoMetaPlugin = (options) => {
6
- options = options || {};
5
+ const InferSeoMetaPlugin = (options = {}) => {
7
6
  return shared.defineHeadPlugin({
8
7
  hooks: {
9
8
  entries: {
10
9
  resolve({ entries }) {
10
+ let titleTemplate = null;
11
+ for (const entry of entries) {
12
+ const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
13
+ const input = entry[inputKey];
14
+ if (typeof input.titleTemplate !== "undefined")
15
+ titleTemplate = input.titleTemplate;
16
+ }
11
17
  for (const entry of entries) {
12
18
  const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
13
19
  const input = entry[inputKey];
14
20
  const resolvedMeta = input.meta || [];
21
+ titleTemplate = shared.resolveTitleTemplate(titleTemplate, input.title);
15
22
  const title = input.title;
16
23
  const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
17
24
  const hasOgTitle = !!resolvedMeta.find((meta) => meta.property === "og:title");
@@ -19,8 +26,8 @@ const InferSeoMetaPlugin = (options) => {
19
26
  const hasTwitterCard = !!resolvedMeta.find((meta) => meta.property === "twitter:card");
20
27
  const hasOgDescription = !!resolvedMeta.find((meta) => meta.property === "og:description");
21
28
  entry[inputKey].meta = input.meta || [];
22
- if (title && !hasOgTitle) {
23
- let newOgTitle = options?.ogTitle || title;
29
+ if (titleTemplate && !hasOgTitle) {
30
+ let newOgTitle = options?.ogTitle || titleTemplate;
24
31
  if (typeof newOgTitle === "function")
25
32
  newOgTitle = newOgTitle(title);
26
33
  if (newOgTitle) {
package/dist/index.mjs CHANGED
@@ -1,15 +1,22 @@
1
- import { defineHeadPlugin } from '@unhead/shared';
1
+ import { defineHeadPlugin, resolveTitleTemplate } from '@unhead/shared';
2
2
 
3
- const InferSeoMetaPlugin = (options) => {
4
- options = options || {};
3
+ const InferSeoMetaPlugin = (options = {}) => {
5
4
  return defineHeadPlugin({
6
5
  hooks: {
7
6
  entries: {
8
7
  resolve({ entries }) {
8
+ let titleTemplate = null;
9
+ for (const entry of entries) {
10
+ const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
11
+ const input = entry[inputKey];
12
+ if (typeof input.titleTemplate !== "undefined")
13
+ titleTemplate = input.titleTemplate;
14
+ }
9
15
  for (const entry of entries) {
10
16
  const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
11
17
  const input = entry[inputKey];
12
18
  const resolvedMeta = input.meta || [];
19
+ titleTemplate = resolveTitleTemplate(titleTemplate, input.title);
13
20
  const title = input.title;
14
21
  const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
15
22
  const hasOgTitle = !!resolvedMeta.find((meta) => meta.property === "og:title");
@@ -17,8 +24,8 @@ const InferSeoMetaPlugin = (options) => {
17
24
  const hasTwitterCard = !!resolvedMeta.find((meta) => meta.property === "twitter:card");
18
25
  const hasOgDescription = !!resolvedMeta.find((meta) => meta.property === "og:description");
19
26
  entry[inputKey].meta = input.meta || [];
20
- if (title && !hasOgTitle) {
21
- let newOgTitle = options?.ogTitle || title;
27
+ if (titleTemplate && !hasOgTitle) {
28
+ let newOgTitle = options?.ogTitle || titleTemplate;
22
29
  if (typeof newOgTitle === "function")
23
30
  newOgTitle = newOgTitle(title);
24
31
  if (newOgTitle) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/addons",
3
3
  "type": "module",
4
- "version": "1.1.19",
4
+ "version": "1.1.20",
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.19",
60
- "@unhead/shared": "1.1.19",
61
- "unhead": "1.1.19"
59
+ "@unhead/schema": "1.1.20",
60
+ "@unhead/shared": "1.1.20",
61
+ "unhead": "1.1.20"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@babel/types": "^7.21.2",