@foundrykit/seo-plugin 0.0.0-stage → 0.3.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/README.md +270 -2
- package/dist/components/JsonLdEditor.d.ts +2 -0
- package/dist/components/JsonLdEditor.js +1184 -0
- package/dist/components/JsonLdEditor.js.map +1 -0
- package/dist/components/JsonLdTemplateRowLabel.d.ts +2 -0
- package/dist/components/JsonLdTemplateRowLabel.js +12 -0
- package/dist/components/JsonLdTemplateRowLabel.js.map +1 -0
- package/dist/components/MetaDescriptionComponent.d.ts +8 -0
- package/dist/components/MetaDescriptionComponent.js +101 -0
- package/dist/components/MetaDescriptionComponent.js.map +1 -0
- package/dist/components/MetaTitleComponent.d.ts +9 -0
- package/dist/components/MetaTitleComponent.js +193 -0
- package/dist/components/MetaTitleComponent.js.map +1 -0
- package/dist/components/OverviewComponent.d.ts +8 -0
- package/dist/components/OverviewComponent.js +64 -0
- package/dist/components/OverviewComponent.js.map +1 -0
- package/dist/components/PreviewComponent.d.ts +8 -0
- package/dist/components/PreviewComponent.js +51 -0
- package/dist/components/PreviewComponent.js.map +1 -0
- package/dist/exports/client.d.ts +6 -0
- package/dist/exports/client.js +8 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/next.d.ts +2 -0
- package/dist/exports/next.js +3 -0
- package/dist/exports/next.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +5 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/fields.d.ts +67 -0
- package/dist/fields.js +220 -0
- package/dist/fields.js.map +1 -0
- package/dist/global.d.ts +6 -0
- package/dist/global.js +93 -0
- package/dist/global.js.map +1 -0
- package/dist/helpers.d.ts +44 -0
- package/dist/helpers.js +23 -0
- package/dist/helpers.js.map +1 -0
- package/dist/helpers.test.d.ts +1 -0
- package/dist/helpers.test.js +234 -0
- package/dist/helpers.test.js.map +1 -0
- package/dist/hooks/autoAlternates.d.ts +18 -0
- package/dist/hooks/autoAlternates.js +63 -0
- package/dist/hooks/autoAlternates.js.map +1 -0
- package/dist/hooks/autoAlternates.test.d.ts +1 -0
- package/dist/hooks/autoAlternates.test.js +225 -0
- package/dist/hooks/autoAlternates.test.js.map +1 -0
- package/dist/hooks/generateMeta.d.ts +17 -0
- package/dist/hooks/generateMeta.js +58 -0
- package/dist/hooks/generateMeta.js.map +1 -0
- package/dist/hooks/generateMeta.test.d.ts +1 -0
- package/dist/hooks/generateMeta.test.js +132 -0
- package/dist/hooks/generateMeta.test.js.map +1 -0
- package/dist/hooks/ogImageGenerator.d.ts +19 -0
- package/dist/hooks/ogImageGenerator.js +96 -0
- package/dist/hooks/ogImageGenerator.js.map +1 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +269 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonld.d.ts +83 -0
- package/dist/jsonld.js +179 -0
- package/dist/jsonld.js.map +1 -0
- package/dist/jsonld.test.d.ts +1 -0
- package/dist/jsonld.test.js +214 -0
- package/dist/jsonld.test.js.map +1 -0
- package/dist/metadata.d.ts +53 -0
- package/dist/metadata.js +114 -0
- package/dist/metadata.js.map +1 -0
- package/dist/metadata.test.d.ts +1 -0
- package/dist/metadata.test.js +286 -0
- package/dist/metadata.test.js.map +1 -0
- package/package.json +100 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useFormFields } from '@payloadcms/ui';
|
|
4
|
+
export const PreviewComponent = ({ descriptionPath, titlePath })=>{
|
|
5
|
+
const title = useFormFields(([fields])=>{
|
|
6
|
+
if (!titlePath) return '';
|
|
7
|
+
return fields[titlePath]?.value ?? '';
|
|
8
|
+
});
|
|
9
|
+
const description = useFormFields(([fields])=>{
|
|
10
|
+
if (!descriptionPath) return '';
|
|
11
|
+
return fields[descriptionPath]?.value ?? '';
|
|
12
|
+
});
|
|
13
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
14
|
+
style: {
|
|
15
|
+
border: '1px solid var(--theme-elevation-150)',
|
|
16
|
+
borderRadius: 4,
|
|
17
|
+
fontFamily: 'Arial, sans-serif',
|
|
18
|
+
maxWidth: 600,
|
|
19
|
+
padding: 12
|
|
20
|
+
},
|
|
21
|
+
children: [
|
|
22
|
+
/*#__PURE__*/ _jsx("div", {
|
|
23
|
+
style: {
|
|
24
|
+
color: '#1a0dab',
|
|
25
|
+
fontSize: 12,
|
|
26
|
+
fontWeight: 500,
|
|
27
|
+
marginBottom: 4
|
|
28
|
+
},
|
|
29
|
+
children: title || 'Page title'
|
|
30
|
+
}),
|
|
31
|
+
/*#__PURE__*/ _jsx("div", {
|
|
32
|
+
style: {
|
|
33
|
+
color: '#006621',
|
|
34
|
+
fontSize: 12,
|
|
35
|
+
marginBottom: 4
|
|
36
|
+
},
|
|
37
|
+
children: "https://example.com/page-url"
|
|
38
|
+
}),
|
|
39
|
+
/*#__PURE__*/ _jsx("div", {
|
|
40
|
+
style: {
|
|
41
|
+
color: '#545454',
|
|
42
|
+
fontSize: 13,
|
|
43
|
+
lineHeight: 1.4
|
|
44
|
+
},
|
|
45
|
+
children: description || 'Page meta description will appear here.'
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=PreviewComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/PreviewComponent.tsx"],"sourcesContent":["'use client';\n\nimport { useFormFields } from '@payloadcms/ui';\nimport type React from 'react';\n\ntype Props = {\n descriptionPath?: string;\n hasGenerateFn?: boolean;\n titlePath?: string;\n};\n\nexport const PreviewComponent: React.FC<Props> = ({\n descriptionPath,\n titlePath,\n}) => {\n const title = useFormFields(([fields]) => {\n if (!titlePath) return '';\n return (fields[titlePath]?.value as string) ?? '';\n });\n\n const description = useFormFields(([fields]) => {\n if (!descriptionPath) return '';\n return (fields[descriptionPath]?.value as string) ?? '';\n });\n\n return (\n <div\n style={{\n border: '1px solid var(--theme-elevation-150)',\n borderRadius: 4,\n fontFamily: 'Arial, sans-serif',\n maxWidth: 600,\n padding: 12,\n }}\n >\n <div\n style={{\n color: '#1a0dab',\n fontSize: 12,\n fontWeight: 500,\n marginBottom: 4,\n }}\n >\n {title || 'Page title'}\n </div>\n <div style={{ color: '#006621', fontSize: 12, marginBottom: 4 }}>\n https://example.com/page-url\n </div>\n <div style={{ color: '#545454', fontSize: 13, lineHeight: 1.4 }}>\n {description || 'Page meta description will appear here.'}\n </div>\n </div>\n );\n};\n"],"names":["useFormFields","PreviewComponent","descriptionPath","titlePath","title","fields","value","description","div","style","border","borderRadius","fontFamily","maxWidth","padding","color","fontSize","fontWeight","marginBottom","lineHeight"],"mappings":"AAAA;;AAEA,SAASA,aAAa,QAAQ,iBAAiB;AAS/C,OAAO,MAAMC,mBAAoC,CAAC,EAChDC,eAAe,EACfC,SAAS,EACV;IACC,MAAMC,QAAQJ,cAAc,CAAC,CAACK,OAAO;QACnC,IAAI,CAACF,WAAW,OAAO;QACvB,OAAO,AAACE,MAAM,CAACF,UAAU,EAAEG,SAAoB;IACjD;IAEA,MAAMC,cAAcP,cAAc,CAAC,CAACK,OAAO;QACzC,IAAI,CAACH,iBAAiB,OAAO;QAC7B,OAAO,AAACG,MAAM,CAACH,gBAAgB,EAAEI,SAAoB;IACvD;IAEA,qBACE,MAACE;QACCC,OAAO;YACLC,QAAQ;YACRC,cAAc;YACdC,YAAY;YACZC,UAAU;YACVC,SAAS;QACX;;0BAEA,KAACN;gBACCC,OAAO;oBACLM,OAAO;oBACPC,UAAU;oBACVC,YAAY;oBACZC,cAAc;gBAChB;0BAECd,SAAS;;0BAEZ,KAACI;gBAAIC,OAAO;oBAAEM,OAAO;oBAAWC,UAAU;oBAAIE,cAAc;gBAAE;0BAAG;;0BAGjE,KAACV;gBAAIC,OAAO;oBAAEM,OAAO;oBAAWC,UAAU;oBAAIG,YAAY;gBAAI;0BAC3DZ,eAAe;;;;AAIxB,EAAE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { JsonLdEditorComponent } from '../components/JsonLdEditor.js';
|
|
2
|
+
export { JsonLdTemplateRowLabel } from '../components/JsonLdTemplateRowLabel.js';
|
|
3
|
+
export { MetaDescriptionComponent } from '../components/MetaDescriptionComponent.js';
|
|
4
|
+
export { MetaTitleComponent } from '../components/MetaTitleComponent.js';
|
|
5
|
+
export { OverviewComponent } from '../components/OverviewComponent.js';
|
|
6
|
+
export { PreviewComponent } from '../components/PreviewComponent.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { JsonLdEditorComponent } from '../components/JsonLdEditor.js';
|
|
2
|
+
export { JsonLdTemplateRowLabel } from '../components/JsonLdTemplateRowLabel.js';
|
|
3
|
+
export { MetaDescriptionComponent } from '../components/MetaDescriptionComponent.js';
|
|
4
|
+
export { MetaTitleComponent } from '../components/MetaTitleComponent.js';
|
|
5
|
+
export { OverviewComponent } from '../components/OverviewComponent.js';
|
|
6
|
+
export { PreviewComponent } from '../components/PreviewComponent.js';
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { JsonLdEditorComponent } from '../components/JsonLdEditor.js';\nexport { JsonLdTemplateRowLabel } from '../components/JsonLdTemplateRowLabel.js';\nexport { MetaDescriptionComponent } from '../components/MetaDescriptionComponent.js';\nexport { MetaTitleComponent } from '../components/MetaTitleComponent.js';\nexport { OverviewComponent } from '../components/OverviewComponent.js';\nexport { PreviewComponent } from '../components/PreviewComponent.js';\n"],"names":["JsonLdEditorComponent","JsonLdTemplateRowLabel","MetaDescriptionComponent","MetaTitleComponent","OverviewComponent","PreviewComponent"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,gCAAgC;AACtE,SAASC,sBAAsB,QAAQ,0CAA0C;AACjF,SAASC,wBAAwB,QAAQ,4CAA4C;AACrF,SAASC,kBAAkB,QAAQ,sCAAsC;AACzE,SAASC,iBAAiB,QAAQ,qCAAqC;AACvE,SAASC,gBAAgB,QAAQ,oCAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/next.ts"],"sourcesContent":["export type { MetadataResult, ToNextMetadataOptions } from '../metadata.js';\nexport { toNextMetadata } from '../metadata.js';\n"],"names":["toNextMetadata"],"mappings":"AACA,SAASA,cAAc,QAAQ,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["// Server component exports for @foundrykit/seo-plugin\n// Reserved for future RSC admin components\nexport {};\n"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,2CAA2C;AAC3C,WAAU"}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ArrayField, CheckboxField, RowField, TextareaField, TextField, UIField, UploadField } from 'payload';
|
|
2
|
+
export type OverviewFieldOptions = {
|
|
3
|
+
descriptionPath?: string;
|
|
4
|
+
imagePath?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
titlePath?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const OverviewField: (opts?: OverviewFieldOptions) => UIField;
|
|
9
|
+
export type MetaTitleFieldOptions = {
|
|
10
|
+
hasGenerateFn?: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
/** Maximum recommended character count. @default 60 */
|
|
13
|
+
max?: number;
|
|
14
|
+
/** Minimum recommended character count. @default 50 */
|
|
15
|
+
min?: number;
|
|
16
|
+
name?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const MetaTitleField: (opts?: MetaTitleFieldOptions) => TextField;
|
|
19
|
+
export type MetaImageFieldOptions = {
|
|
20
|
+
label?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
relationTo?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare const MetaImageField: (opts?: MetaImageFieldOptions) => UploadField;
|
|
25
|
+
export type MetaDescriptionFieldOptions = {
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Maximum recommended character count. @default 150 */
|
|
28
|
+
max?: number;
|
|
29
|
+
/** Minimum recommended character count. @default 100 */
|
|
30
|
+
min?: number;
|
|
31
|
+
name?: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const MetaDescriptionField: (opts?: MetaDescriptionFieldOptions) => TextareaField;
|
|
34
|
+
export type MetaPreviewFieldOptions = {
|
|
35
|
+
descriptionPath?: string;
|
|
36
|
+
hasGenerateFn?: boolean;
|
|
37
|
+
name?: string;
|
|
38
|
+
position?: 'sidebar';
|
|
39
|
+
titlePath?: string;
|
|
40
|
+
};
|
|
41
|
+
export declare const MetaPreviewField: (opts?: MetaPreviewFieldOptions) => UIField;
|
|
42
|
+
export type MetaUrlFieldOptions = {
|
|
43
|
+
label?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
};
|
|
46
|
+
export declare const MetaUrlField: (opts?: MetaUrlFieldOptions) => TextField;
|
|
47
|
+
export type MetaNoindexFieldOptions = {
|
|
48
|
+
label?: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
};
|
|
51
|
+
export declare const MetaNoindexField: (opts?: MetaNoindexFieldOptions) => CheckboxField;
|
|
52
|
+
export type MetaNofollowFieldOptions = {
|
|
53
|
+
label?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
};
|
|
56
|
+
export declare const MetaNofollowField: (opts?: MetaNofollowFieldOptions) => CheckboxField;
|
|
57
|
+
export type MetaAlternatesFieldOptions = {
|
|
58
|
+
label?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
};
|
|
61
|
+
export declare const MetaAlternatesField: (opts?: MetaAlternatesFieldOptions) => ArrayField;
|
|
62
|
+
export type MetaJsonLdFieldOptions = {
|
|
63
|
+
label?: string;
|
|
64
|
+
name?: string;
|
|
65
|
+
};
|
|
66
|
+
export declare const MetaJsonLdField: (opts?: MetaJsonLdFieldOptions) => import("payload").JSONField;
|
|
67
|
+
export declare const structuredDataRow: RowField;
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
export const OverviewField = (opts = {})=>({
|
|
2
|
+
name: opts.name ?? 'overview',
|
|
3
|
+
type: 'ui',
|
|
4
|
+
admin: {
|
|
5
|
+
components: {
|
|
6
|
+
Field: {
|
|
7
|
+
clientProps: {
|
|
8
|
+
descriptionPath: opts.descriptionPath,
|
|
9
|
+
imagePath: opts.imagePath,
|
|
10
|
+
titlePath: opts.titlePath
|
|
11
|
+
},
|
|
12
|
+
path: '@foundrykit/seo-plugin/client#OverviewComponent'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
export const MetaTitleField = (opts = {})=>({
|
|
18
|
+
name: opts.name ?? 'metaTitle',
|
|
19
|
+
type: 'text',
|
|
20
|
+
admin: {
|
|
21
|
+
components: {
|
|
22
|
+
Field: {
|
|
23
|
+
clientProps: {
|
|
24
|
+
hasGenerateFn: opts.hasGenerateFn ?? false,
|
|
25
|
+
max: opts.max ?? 60,
|
|
26
|
+
min: opts.min ?? 50
|
|
27
|
+
},
|
|
28
|
+
path: '@foundrykit/seo-plugin/client#MetaTitleComponent'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
label: opts.label ?? 'Meta Title'
|
|
33
|
+
});
|
|
34
|
+
export const MetaImageField = (opts = {})=>({
|
|
35
|
+
name: opts.name ?? 'metaImage',
|
|
36
|
+
type: 'upload',
|
|
37
|
+
label: opts.label ?? 'Meta Image',
|
|
38
|
+
relationTo: opts.relationTo ?? 'media'
|
|
39
|
+
});
|
|
40
|
+
export const MetaDescriptionField = (opts = {})=>({
|
|
41
|
+
name: opts.name ?? 'metaDescription',
|
|
42
|
+
type: 'textarea',
|
|
43
|
+
admin: {
|
|
44
|
+
components: {
|
|
45
|
+
Field: {
|
|
46
|
+
clientProps: {
|
|
47
|
+
max: opts.max ?? 150,
|
|
48
|
+
min: opts.min ?? 100
|
|
49
|
+
},
|
|
50
|
+
path: '@foundrykit/seo-plugin/client#MetaDescriptionComponent'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
label: opts.label ?? 'Meta Description'
|
|
55
|
+
});
|
|
56
|
+
export const MetaPreviewField = (opts = {})=>({
|
|
57
|
+
name: opts.name ?? 'preview',
|
|
58
|
+
type: 'ui',
|
|
59
|
+
admin: {
|
|
60
|
+
components: {
|
|
61
|
+
Field: {
|
|
62
|
+
clientProps: {
|
|
63
|
+
descriptionPath: opts.descriptionPath,
|
|
64
|
+
hasGenerateFn: opts.hasGenerateFn,
|
|
65
|
+
titlePath: opts.titlePath
|
|
66
|
+
},
|
|
67
|
+
path: '@foundrykit/seo-plugin/client#PreviewComponent'
|
|
68
|
+
},
|
|
69
|
+
position: opts.position
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
export const MetaUrlField = (opts = {})=>({
|
|
74
|
+
name: opts.name ?? 'canonicalUrl',
|
|
75
|
+
type: 'text',
|
|
76
|
+
admin: {
|
|
77
|
+
description: 'Absolute canonical URL for this page. Auto-populated if generateURL is configured.'
|
|
78
|
+
},
|
|
79
|
+
label: opts.label ?? 'Canonical URL'
|
|
80
|
+
});
|
|
81
|
+
export const MetaNoindexField = (opts = {})=>({
|
|
82
|
+
name: opts.name ?? 'noindex',
|
|
83
|
+
type: 'checkbox',
|
|
84
|
+
admin: {
|
|
85
|
+
description: 'Instruct search engines not to index this page.'
|
|
86
|
+
},
|
|
87
|
+
defaultValue: false,
|
|
88
|
+
label: opts.label ?? 'No Index'
|
|
89
|
+
});
|
|
90
|
+
export const MetaNofollowField = (opts = {})=>({
|
|
91
|
+
name: opts.name ?? 'nofollow',
|
|
92
|
+
type: 'checkbox',
|
|
93
|
+
admin: {
|
|
94
|
+
description: 'Instruct search engines not to follow links on this page.'
|
|
95
|
+
},
|
|
96
|
+
defaultValue: false,
|
|
97
|
+
label: opts.label ?? 'No Follow'
|
|
98
|
+
});
|
|
99
|
+
export const MetaAlternatesField = (opts = {})=>({
|
|
100
|
+
name: opts.name ?? 'alternates',
|
|
101
|
+
type: 'array',
|
|
102
|
+
admin: {
|
|
103
|
+
description: 'Add hreflang alternate URLs for each locale this page is available in.'
|
|
104
|
+
},
|
|
105
|
+
fields: [
|
|
106
|
+
{
|
|
107
|
+
name: 'locale',
|
|
108
|
+
type: 'text',
|
|
109
|
+
admin: {
|
|
110
|
+
description: 'BCP 47 locale tag, e.g. en, en-US, fr, de',
|
|
111
|
+
width: '30%'
|
|
112
|
+
},
|
|
113
|
+
label: 'Locale',
|
|
114
|
+
required: true
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'url',
|
|
118
|
+
type: 'text',
|
|
119
|
+
admin: {
|
|
120
|
+
description: 'Absolute URL for this locale, e.g. https://example.com/fr/page',
|
|
121
|
+
width: '70%'
|
|
122
|
+
},
|
|
123
|
+
label: 'URL',
|
|
124
|
+
required: true
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
label: opts.label ?? 'Hreflang Alternates'
|
|
128
|
+
});
|
|
129
|
+
export const MetaJsonLdField = (opts = {})=>({
|
|
130
|
+
name: opts.name ?? 'jsonLd',
|
|
131
|
+
type: 'json',
|
|
132
|
+
admin: {
|
|
133
|
+
components: {
|
|
134
|
+
Field: '@foundrykit/seo-plugin/client#JsonLdEditorComponent'
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
label: opts.label ?? 'JSON-LD Structured Data',
|
|
138
|
+
validate: validateJsonLd
|
|
139
|
+
});
|
|
140
|
+
const KNOWN_SCHEMA_TYPES = [
|
|
141
|
+
'WebPage',
|
|
142
|
+
'Article',
|
|
143
|
+
'Product',
|
|
144
|
+
'Organization',
|
|
145
|
+
'BreadcrumbList'
|
|
146
|
+
];
|
|
147
|
+
const REQUIRED_FIELDS_BY_TYPE = {
|
|
148
|
+
Article: [
|
|
149
|
+
'headline'
|
|
150
|
+
],
|
|
151
|
+
BreadcrumbList: [
|
|
152
|
+
'itemListElement'
|
|
153
|
+
],
|
|
154
|
+
Organization: [
|
|
155
|
+
'name'
|
|
156
|
+
],
|
|
157
|
+
Product: [
|
|
158
|
+
'name'
|
|
159
|
+
],
|
|
160
|
+
WebPage: []
|
|
161
|
+
};
|
|
162
|
+
function validateJsonLd(value) {
|
|
163
|
+
// Empty / null is fine — schema markup is optional
|
|
164
|
+
if (value === null || value === undefined) return true;
|
|
165
|
+
// Payload may pass the value as a JSON string — parse it
|
|
166
|
+
let obj;
|
|
167
|
+
if (typeof value === 'string') {
|
|
168
|
+
if (value.trim() === '' || value.trim() === '{}') return true;
|
|
169
|
+
try {
|
|
170
|
+
const parsed = JSON.parse(value);
|
|
171
|
+
if (typeof parsed !== 'object' || Array.isArray(parsed) || parsed === null) {
|
|
172
|
+
return 'Structured data must be a JSON object.';
|
|
173
|
+
}
|
|
174
|
+
obj = parsed;
|
|
175
|
+
} catch {
|
|
176
|
+
return 'Structured data contains invalid JSON.';
|
|
177
|
+
}
|
|
178
|
+
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
179
|
+
if (Object.keys(value).length === 0) return true;
|
|
180
|
+
obj = value;
|
|
181
|
+
} else {
|
|
182
|
+
return 'Structured data must be a JSON object.';
|
|
183
|
+
}
|
|
184
|
+
if (obj['@context'] !== 'https://schema.org') {
|
|
185
|
+
return 'Structured data must have "@context": "https://schema.org".';
|
|
186
|
+
}
|
|
187
|
+
const type = obj['@type'];
|
|
188
|
+
if (!type) {
|
|
189
|
+
return 'Structured data must have an "@type" property.';
|
|
190
|
+
}
|
|
191
|
+
if (!KNOWN_SCHEMA_TYPES.includes(type)) {
|
|
192
|
+
return `Unknown schema type "${type}". Expected one of: ${KNOWN_SCHEMA_TYPES.join(', ')}.`;
|
|
193
|
+
}
|
|
194
|
+
const required = REQUIRED_FIELDS_BY_TYPE[type] ?? [];
|
|
195
|
+
for (const field of required){
|
|
196
|
+
if (!obj[field]) {
|
|
197
|
+
return `Schema type "${type}" requires the "${field}" field.`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (type === 'BreadcrumbList') {
|
|
201
|
+
const items = obj.itemListElement;
|
|
202
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
203
|
+
return 'BreadcrumbList requires at least one item in "itemListElement".';
|
|
204
|
+
}
|
|
205
|
+
for (const [i, item] of items.entries()){
|
|
206
|
+
const it = item;
|
|
207
|
+
if (!it.name) return `Breadcrumb item ${i + 1} is missing a "name".`;
|
|
208
|
+
if (!it.item) return `Breadcrumb item ${i + 1} is missing a URL ("item").`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
export const structuredDataRow = {
|
|
214
|
+
type: 'row',
|
|
215
|
+
fields: [
|
|
216
|
+
MetaJsonLdField()
|
|
217
|
+
]
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fields.ts"],"sourcesContent":["import type {\n ArrayField,\n CheckboxField,\n RowField,\n TextareaField,\n TextField,\n UIField,\n UploadField,\n} from 'payload';\n\nexport type OverviewFieldOptions = {\n descriptionPath?: string;\n imagePath?: string;\n name?: string;\n titlePath?: string;\n};\n\nexport const OverviewField = (opts: OverviewFieldOptions = {}): UIField => ({\n name: opts.name ?? 'overview',\n type: 'ui',\n admin: {\n components: {\n Field: {\n clientProps: {\n descriptionPath: opts.descriptionPath,\n imagePath: opts.imagePath,\n titlePath: opts.titlePath,\n },\n path: '@foundrykit/seo-plugin/client#OverviewComponent',\n },\n },\n },\n});\n\nexport type MetaTitleFieldOptions = {\n hasGenerateFn?: boolean;\n label?: string;\n /** Maximum recommended character count. @default 60 */\n max?: number;\n /** Minimum recommended character count. @default 50 */\n min?: number;\n name?: string;\n};\n\nexport const MetaTitleField = (\n opts: MetaTitleFieldOptions = {}\n): TextField => ({\n name: opts.name ?? 'metaTitle',\n type: 'text',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateFn: opts.hasGenerateFn ?? false,\n max: opts.max ?? 60,\n min: opts.min ?? 50,\n },\n path: '@foundrykit/seo-plugin/client#MetaTitleComponent',\n },\n },\n },\n label: opts.label ?? 'Meta Title',\n});\n\nexport type MetaImageFieldOptions = {\n label?: string;\n name?: string;\n relationTo?: string;\n};\n\nexport const MetaImageField = (\n opts: MetaImageFieldOptions = {}\n): UploadField => ({\n name: opts.name ?? 'metaImage',\n type: 'upload',\n label: opts.label ?? 'Meta Image',\n relationTo: (opts.relationTo ?? 'media') as 'media',\n});\n\nexport type MetaDescriptionFieldOptions = {\n label?: string;\n /** Maximum recommended character count. @default 150 */\n max?: number;\n /** Minimum recommended character count. @default 100 */\n min?: number;\n name?: string;\n};\n\nexport const MetaDescriptionField = (\n opts: MetaDescriptionFieldOptions = {}\n): TextareaField => ({\n name: opts.name ?? 'metaDescription',\n type: 'textarea',\n admin: {\n components: {\n Field: {\n clientProps: {\n max: opts.max ?? 150,\n min: opts.min ?? 100,\n },\n path: '@foundrykit/seo-plugin/client#MetaDescriptionComponent',\n },\n },\n },\n label: opts.label ?? 'Meta Description',\n});\n\nexport type MetaPreviewFieldOptions = {\n descriptionPath?: string;\n hasGenerateFn?: boolean;\n name?: string;\n position?: 'sidebar';\n titlePath?: string;\n};\n\nexport const MetaPreviewField = (\n opts: MetaPreviewFieldOptions = {}\n): UIField => ({\n name: opts.name ?? 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: {\n clientProps: {\n descriptionPath: opts.descriptionPath,\n hasGenerateFn: opts.hasGenerateFn,\n titlePath: opts.titlePath,\n },\n path: '@foundrykit/seo-plugin/client#PreviewComponent',\n },\n position: opts.position,\n },\n },\n});\n\nexport type MetaUrlFieldOptions = {\n label?: string;\n name?: string;\n};\n\nexport const MetaUrlField = (opts: MetaUrlFieldOptions = {}): TextField => ({\n name: opts.name ?? 'canonicalUrl',\n type: 'text',\n admin: {\n description:\n 'Absolute canonical URL for this page. Auto-populated if generateURL is configured.',\n },\n label: opts.label ?? 'Canonical URL',\n});\n\nexport type MetaNoindexFieldOptions = {\n label?: string;\n name?: string;\n};\n\nexport const MetaNoindexField = (\n opts: MetaNoindexFieldOptions = {}\n): CheckboxField => ({\n name: opts.name ?? 'noindex',\n type: 'checkbox',\n admin: {\n description: 'Instruct search engines not to index this page.',\n },\n defaultValue: false,\n label: opts.label ?? 'No Index',\n});\n\nexport type MetaNofollowFieldOptions = {\n label?: string;\n name?: string;\n};\n\nexport const MetaNofollowField = (\n opts: MetaNofollowFieldOptions = {}\n): CheckboxField => ({\n name: opts.name ?? 'nofollow',\n type: 'checkbox',\n admin: {\n description: 'Instruct search engines not to follow links on this page.',\n },\n defaultValue: false,\n label: opts.label ?? 'No Follow',\n});\n\nexport type MetaAlternatesFieldOptions = {\n label?: string;\n name?: string;\n};\n\nexport const MetaAlternatesField = (\n opts: MetaAlternatesFieldOptions = {}\n): ArrayField => ({\n name: opts.name ?? 'alternates',\n type: 'array',\n admin: {\n description:\n 'Add hreflang alternate URLs for each locale this page is available in.',\n },\n fields: [\n {\n name: 'locale',\n type: 'text',\n admin: {\n description: 'BCP 47 locale tag, e.g. en, en-US, fr, de',\n width: '30%',\n },\n label: 'Locale',\n required: true,\n },\n {\n name: 'url',\n type: 'text',\n admin: {\n description:\n 'Absolute URL for this locale, e.g. https://example.com/fr/page',\n width: '70%',\n },\n label: 'URL',\n required: true,\n },\n ],\n label: opts.label ?? 'Hreflang Alternates',\n});\n\nexport type MetaJsonLdFieldOptions = {\n label?: string;\n name?: string;\n};\n\nexport const MetaJsonLdField = (\n opts: MetaJsonLdFieldOptions = {}\n): import('payload').JSONField => ({\n name: opts.name ?? 'jsonLd',\n type: 'json',\n admin: {\n components: {\n Field: '@foundrykit/seo-plugin/client#JsonLdEditorComponent',\n },\n },\n label: opts.label ?? 'JSON-LD Structured Data',\n validate: validateJsonLd,\n});\n\nconst KNOWN_SCHEMA_TYPES = [\n 'WebPage',\n 'Article',\n 'Product',\n 'Organization',\n 'BreadcrumbList',\n];\n\nconst REQUIRED_FIELDS_BY_TYPE: Record<string, string[]> = {\n Article: ['headline'],\n BreadcrumbList: ['itemListElement'],\n Organization: ['name'],\n Product: ['name'],\n WebPage: [],\n};\n\nfunction validateJsonLd(value: unknown): string | true {\n // Empty / null is fine — schema markup is optional\n if (value === null || value === undefined) return true;\n\n // Payload may pass the value as a JSON string — parse it\n let obj: Record<string, unknown>;\n if (typeof value === 'string') {\n if (value.trim() === '' || value.trim() === '{}') return true;\n try {\n const parsed = JSON.parse(value) as unknown;\n if (\n typeof parsed !== 'object' ||\n Array.isArray(parsed) ||\n parsed === null\n ) {\n return 'Structured data must be a JSON object.';\n }\n obj = parsed as Record<string, unknown>;\n } catch {\n return 'Structured data contains invalid JSON.';\n }\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n if (Object.keys(value as object).length === 0) return true;\n obj = value as Record<string, unknown>;\n } else {\n return 'Structured data must be a JSON object.';\n }\n\n if (obj['@context'] !== 'https://schema.org') {\n return 'Structured data must have \"@context\": \"https://schema.org\".';\n }\n\n const type = obj['@type'] as string | undefined;\n if (!type) {\n return 'Structured data must have an \"@type\" property.';\n }\n\n if (!KNOWN_SCHEMA_TYPES.includes(type)) {\n return `Unknown schema type \"${type}\". Expected one of: ${KNOWN_SCHEMA_TYPES.join(', ')}.`;\n }\n\n const required = REQUIRED_FIELDS_BY_TYPE[type] ?? [];\n for (const field of required) {\n if (!obj[field]) {\n return `Schema type \"${type}\" requires the \"${field}\" field.`;\n }\n }\n\n if (type === 'BreadcrumbList') {\n const items = obj.itemListElement;\n if (!Array.isArray(items) || items.length === 0) {\n return 'BreadcrumbList requires at least one item in \"itemListElement\".';\n }\n for (const [i, item] of (items as unknown[]).entries()) {\n const it = item as Record<string, unknown>;\n if (!it.name) return `Breadcrumb item ${i + 1} is missing a \"name\".`;\n if (!it.item)\n return `Breadcrumb item ${i + 1} is missing a URL (\"item\").`;\n }\n }\n\n return true;\n}\n\nexport const structuredDataRow: RowField = {\n type: 'row',\n fields: [MetaJsonLdField()],\n};\n"],"names":["OverviewField","opts","name","type","admin","components","Field","clientProps","descriptionPath","imagePath","titlePath","path","MetaTitleField","hasGenerateFn","max","min","label","MetaImageField","relationTo","MetaDescriptionField","MetaPreviewField","position","MetaUrlField","description","MetaNoindexField","defaultValue","MetaNofollowField","MetaAlternatesField","fields","width","required","MetaJsonLdField","validate","validateJsonLd","KNOWN_SCHEMA_TYPES","REQUIRED_FIELDS_BY_TYPE","Article","BreadcrumbList","Organization","Product","WebPage","value","undefined","obj","trim","parsed","JSON","parse","Array","isArray","Object","keys","length","includes","join","field","items","itemListElement","i","item","entries","it","structuredDataRow"],"mappings":"AAiBA,OAAO,MAAMA,gBAAgB,CAACC,OAA6B,CAAC,CAAC,GAAe,CAAA;QAC1EC,MAAMD,KAAKC,IAAI,IAAI;QACnBC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,iBAAiBP,KAAKO,eAAe;wBACrCC,WAAWR,KAAKQ,SAAS;wBACzBC,WAAWT,KAAKS,SAAS;oBAC3B;oBACAC,MAAM;gBACR;YACF;QACF;IACF,CAAA,EAAG;AAYH,OAAO,MAAMC,iBAAiB,CAC5BX,OAA8B,CAAC,CAAC,GACjB,CAAA;QACfC,MAAMD,KAAKC,IAAI,IAAI;QACnBC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXM,eAAeZ,KAAKY,aAAa,IAAI;wBACrCC,KAAKb,KAAKa,GAAG,IAAI;wBACjBC,KAAKd,KAAKc,GAAG,IAAI;oBACnB;oBACAJ,MAAM;gBACR;YACF;QACF;QACAK,OAAOf,KAAKe,KAAK,IAAI;IACvB,CAAA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,GAAG3D,IAAI,EAAE,OAAO,CAAC,gBAAgB,EAAEwD,IAAI,EAAE,qBAAqB,CAAC;YACpE,IAAI,CAACG,GAAGF,IAAI,EACV,OAAO,CAAC,gBAAgB,EAAED,IAAI,EAAE,2BAA2B,CAAC;QAChE;IACF;IAEA,OAAO;AACT;AAEA,OAAO,MAAMI,oBAA8B;IACzC3D,MAAM;IACNyB,QAAQ;QAACG;KAAkB;AAC7B,EAAE"}
|
package/dist/global.d.ts
ADDED
package/dist/global.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const getGlobalSeoGlobal = (opts = {})=>{
|
|
2
|
+
const mediaRelation = opts.mediaCollection?.[0] ?? 'media';
|
|
3
|
+
return {
|
|
4
|
+
slug: 'global-seo',
|
|
5
|
+
fields: [
|
|
6
|
+
{
|
|
7
|
+
name: 'siteName',
|
|
8
|
+
type: 'text',
|
|
9
|
+
label: 'Site Name'
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'twitterHandle',
|
|
13
|
+
type: 'text',
|
|
14
|
+
label: 'Twitter / X Handle'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'robots',
|
|
18
|
+
type: 'text',
|
|
19
|
+
admin: {
|
|
20
|
+
description: 'Override robots meta tag for all pages — useful for staging (e.g. "noindex, nofollow"). Leave blank for production.',
|
|
21
|
+
placeholder: 'noindex, nofollow'
|
|
22
|
+
},
|
|
23
|
+
label: 'Site-wide Robots Directive'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'defaultTitle',
|
|
27
|
+
type: 'text',
|
|
28
|
+
label: 'Default Meta Title'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'defaultDescription',
|
|
32
|
+
type: 'textarea',
|
|
33
|
+
label: 'Default Meta Description'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'defaultImage',
|
|
37
|
+
type: 'upload',
|
|
38
|
+
label: 'Default OG Image',
|
|
39
|
+
relationTo: mediaRelation
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'autoGenerateAlternates',
|
|
43
|
+
type: 'checkbox',
|
|
44
|
+
defaultValue: false,
|
|
45
|
+
label: 'Auto-generate Hreflang Alternates'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'enableOgGenerator',
|
|
49
|
+
type: 'checkbox',
|
|
50
|
+
defaultValue: false,
|
|
51
|
+
label: 'Enable OG Image Generator'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'jsonLdTemplates',
|
|
55
|
+
type: 'array',
|
|
56
|
+
admin: {
|
|
57
|
+
components: {
|
|
58
|
+
RowLabel: '@foundrykit/seo-plugin/client#JsonLdTemplateRowLabel'
|
|
59
|
+
},
|
|
60
|
+
description: 'Reusable schema markup templates. The five built-in schema types are seeded automatically — customise them or add your own. Each template can be loaded into any document from the JSON-LD field.',
|
|
61
|
+
initCollapsed: false
|
|
62
|
+
},
|
|
63
|
+
fields: [
|
|
64
|
+
{
|
|
65
|
+
name: 'name',
|
|
66
|
+
type: 'text',
|
|
67
|
+
label: 'Template Name',
|
|
68
|
+
required: true
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'template',
|
|
72
|
+
type: 'json',
|
|
73
|
+
admin: {
|
|
74
|
+
components: {
|
|
75
|
+
Field: {
|
|
76
|
+
clientProps: {
|
|
77
|
+
isTemplate: true
|
|
78
|
+
},
|
|
79
|
+
path: '@foundrykit/seo-plugin/client#JsonLdEditorComponent'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
label: 'Schema'
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
label: 'JSON-LD Templates'
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
label: 'Global SEO'
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/global.ts"],"sourcesContent":["import type { GlobalConfig } from 'payload';\n\ntype GlobalSeoOptions = {\n mediaCollection?: string[];\n};\n\nexport const getGlobalSeoGlobal = (\n opts: GlobalSeoOptions = {}\n): GlobalConfig => {\n const mediaRelation = (opts.mediaCollection?.[0] ?? 'media') as 'media';\n\n return {\n slug: 'global-seo',\n fields: [\n {\n name: 'siteName',\n type: 'text',\n label: 'Site Name',\n },\n {\n name: 'twitterHandle',\n type: 'text',\n label: 'Twitter / X Handle',\n },\n {\n name: 'robots',\n type: 'text',\n admin: {\n description:\n 'Override robots meta tag for all pages — useful for staging (e.g. \"noindex, nofollow\"). Leave blank for production.',\n placeholder: 'noindex, nofollow',\n },\n label: 'Site-wide Robots Directive',\n },\n {\n name: 'defaultTitle',\n type: 'text',\n label: 'Default Meta Title',\n },\n {\n name: 'defaultDescription',\n type: 'textarea',\n label: 'Default Meta Description',\n },\n {\n name: 'defaultImage',\n type: 'upload',\n label: 'Default OG Image',\n relationTo: mediaRelation,\n },\n {\n name: 'autoGenerateAlternates',\n type: 'checkbox',\n defaultValue: false,\n label: 'Auto-generate Hreflang Alternates',\n },\n {\n name: 'enableOgGenerator',\n type: 'checkbox',\n defaultValue: false,\n label: 'Enable OG Image Generator',\n },\n {\n name: 'jsonLdTemplates',\n type: 'array',\n admin: {\n components: {\n RowLabel: '@foundrykit/seo-plugin/client#JsonLdTemplateRowLabel',\n },\n description:\n 'Reusable schema markup templates. The five built-in schema types are seeded automatically — customise them or add your own. Each template can be loaded into any document from the JSON-LD field.',\n initCollapsed: false,\n },\n fields: [\n {\n name: 'name',\n type: 'text',\n label: 'Template Name',\n required: true,\n },\n {\n name: 'template',\n type: 'json',\n admin: {\n components: {\n Field: {\n clientProps: { isTemplate: true },\n path: '@foundrykit/seo-plugin/client#JsonLdEditorComponent',\n },\n },\n },\n label: 'Schema',\n },\n ],\n label: 'JSON-LD Templates',\n },\n ],\n label: 'Global SEO',\n };\n};\n"],"names":["getGlobalSeoGlobal","opts","mediaRelation","mediaCollection","slug","fields","name","type","label","admin","description","placeholder","relationTo","defaultValue","components","RowLabel","initCollapsed","required","Field","clientProps","isTemplate","path"],"mappings":"AAMA,OAAO,MAAMA,qBAAqB,CAChCC,OAAyB,CAAC,CAAC;IAE3B,MAAMC,gBAAiBD,KAAKE,eAAe,EAAE,CAAC,EAAE,IAAI;IAEpD,OAAO;QACLC,MAAM;QACNC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNE,OAAO;oBACLC,aACE;oBACFC,aAAa;gBACf;gBACAH,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNC,OAAO;gBACPI,YAAYV;YACd;YACA;gBACEI,MAAM;gBACNC,MAAM;gBACNM,cAAc;gBACdL,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNM,cAAc;gBACdL,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNE,OAAO;oBACLK,YAAY;wBACVC,UAAU;oBACZ;oBACAL,aACE;oBACFM,eAAe;gBACjB;gBACAX,QAAQ;oBACN;wBACEC,MAAM;wBACNC,MAAM;wBACNC,OAAO;wBACPS,UAAU;oBACZ;oBACA;wBACEX,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLK,YAAY;gCACVI,OAAO;oCACLC,aAAa;wCAAEC,YAAY;oCAAK;oCAChCC,MAAM;gCACR;4BACF;wBACF;wBACAb,OAAO;oBACT;iBACD;gBACDA,OAAO;YACT;SACD;QACDA,OAAO;IACT;AACF,EAAE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type Alternate = {
|
|
2
|
+
locale: string;
|
|
3
|
+
url: string;
|
|
4
|
+
};
|
|
5
|
+
export type GlobalSeoDefaults = {
|
|
6
|
+
autoGenerateAlternates?: boolean;
|
|
7
|
+
defaultDescription?: string;
|
|
8
|
+
defaultImage?: {
|
|
9
|
+
url?: string;
|
|
10
|
+
} | null | string;
|
|
11
|
+
defaultTitle?: string;
|
|
12
|
+
robots?: string;
|
|
13
|
+
twitterHandle?: string;
|
|
14
|
+
};
|
|
15
|
+
export type DocWithMeta = {
|
|
16
|
+
description?: string;
|
|
17
|
+
meta?: {
|
|
18
|
+
alternates?: Alternate[];
|
|
19
|
+
description?: string;
|
|
20
|
+
image?: {
|
|
21
|
+
url?: string;
|
|
22
|
+
} | null | string;
|
|
23
|
+
jsonLd?: null | Record<string, unknown>;
|
|
24
|
+
nofollow?: boolean;
|
|
25
|
+
noindex?: boolean;
|
|
26
|
+
title?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
};
|
|
29
|
+
slug?: string;
|
|
30
|
+
title?: string;
|
|
31
|
+
};
|
|
32
|
+
export type ResolvedMeta = {
|
|
33
|
+
alternates: Alternate[];
|
|
34
|
+
description: string;
|
|
35
|
+
image: null | string;
|
|
36
|
+
jsonLd: null | Record<string, unknown>;
|
|
37
|
+
nofollow: boolean;
|
|
38
|
+
noindex: boolean;
|
|
39
|
+
title: string;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
export declare const resolveMeta: (doc: DocWithMeta, { globals }?: {
|
|
43
|
+
globals?: GlobalSeoDefaults;
|
|
44
|
+
}) => ResolvedMeta;
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const resolveMeta = (doc, { globals } = {})=>{
|
|
2
|
+
const g = globals ?? {};
|
|
3
|
+
const meta = doc?.meta ?? {};
|
|
4
|
+
const rawImage = meta.image ?? g.defaultImage ?? null;
|
|
5
|
+
const image = rawImage && typeof rawImage === 'object' && 'url' in rawImage ? rawImage.url ?? null : typeof rawImage === 'string' ? rawImage : null;
|
|
6
|
+
// Manual alternates from the document take precedence.
|
|
7
|
+
// Auto-generation (when g.autoGenerateAlternates is true) is handled
|
|
8
|
+
// at the hook level before resolveMeta is called, so by the time we
|
|
9
|
+
// get here the alternates array is already populated.
|
|
10
|
+
const alternates = meta.alternates ?? [];
|
|
11
|
+
return {
|
|
12
|
+
alternates,
|
|
13
|
+
description: meta.description ?? g.defaultDescription ?? doc.description ?? '',
|
|
14
|
+
image,
|
|
15
|
+
jsonLd: meta.jsonLd ?? null,
|
|
16
|
+
nofollow: meta.nofollow ?? false,
|
|
17
|
+
noindex: meta.noindex ?? false,
|
|
18
|
+
title: meta.title ?? g.defaultTitle ?? doc.title ?? '',
|
|
19
|
+
url: meta.url ?? ''
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["export type Alternate = {\n locale: string;\n url: string;\n};\n\nexport type GlobalSeoDefaults = {\n autoGenerateAlternates?: boolean;\n defaultDescription?: string;\n defaultImage?: { url?: string } | null | string;\n defaultTitle?: string;\n robots?: string;\n twitterHandle?: string;\n};\n\nexport type DocWithMeta = {\n description?: string;\n meta?: {\n alternates?: Alternate[];\n description?: string;\n image?: { url?: string } | null | string;\n jsonLd?: null | Record<string, unknown>;\n nofollow?: boolean;\n noindex?: boolean;\n title?: string;\n url?: string;\n };\n slug?: string;\n title?: string;\n};\n\nexport type ResolvedMeta = {\n alternates: Alternate[];\n description: string;\n image: null | string;\n jsonLd: null | Record<string, unknown>;\n nofollow: boolean;\n noindex: boolean;\n title: string;\n url: string;\n};\n\nexport const resolveMeta = (\n doc: DocWithMeta,\n { globals }: { globals?: GlobalSeoDefaults } = {}\n): ResolvedMeta => {\n const g = globals ?? {};\n const meta = doc?.meta ?? {};\n\n const rawImage = meta.image ?? g.defaultImage ?? null;\n const image =\n rawImage && typeof rawImage === 'object' && 'url' in rawImage\n ? (rawImage.url ?? null)\n : typeof rawImage === 'string'\n ? rawImage\n : null;\n\n // Manual alternates from the document take precedence.\n // Auto-generation (when g.autoGenerateAlternates is true) is handled\n // at the hook level before resolveMeta is called, so by the time we\n // get here the alternates array is already populated.\n const alternates: Alternate[] = meta.alternates ?? [];\n\n return {\n alternates,\n description:\n meta.description ?? g.defaultDescription ?? doc.description ?? '',\n image,\n jsonLd: meta.jsonLd ?? null,\n nofollow: meta.nofollow ?? false,\n noindex: meta.noindex ?? false,\n title: meta.title ?? g.defaultTitle ?? doc.title ?? '',\n url: meta.url ?? '',\n };\n};\n"],"names":["resolveMeta","doc","globals","g","meta","rawImage","image","defaultImage","url","alternates","description","defaultDescription","jsonLd","nofollow","noindex","title","defaultTitle"],"mappings":"AAyCA,OAAO,MAAMA,cAAc,CACzBC,KACA,EAAEC,OAAO,EAAmC,GAAG,CAAC,CAAC;IAEjD,MAAMC,IAAID,WAAW,CAAC;IACtB,MAAME,OAAOH,KAAKG,QAAQ,CAAC;IAE3B,MAAMC,WAAWD,KAAKE,KAAK,IAAIH,EAAEI,YAAY,IAAI;IACjD,MAAMD,QACJD,YAAY,OAAOA,aAAa,YAAY,SAASA,WAChDA,SAASG,GAAG,IAAI,OACjB,OAAOH,aAAa,WAClBA,WACA;IAER,uDAAuD;IACvD,qEAAqE;IACrE,oEAAoE;IACpE,sDAAsD;IACtD,MAAMI,aAA0BL,KAAKK,UAAU,IAAI,EAAE;IAErD,OAAO;QACLA;QACAC,aACEN,KAAKM,WAAW,IAAIP,EAAEQ,kBAAkB,IAAIV,IAAIS,WAAW,IAAI;QACjEJ;QACAM,QAAQR,KAAKQ,MAAM,IAAI;QACvBC,UAAUT,KAAKS,QAAQ,IAAI;QAC3BC,SAASV,KAAKU,OAAO,IAAI;QACzBC,OAAOX,KAAKW,KAAK,IAAIZ,EAAEa,YAAY,IAAIf,IAAIc,KAAK,IAAI;QACpDP,KAAKJ,KAAKI,GAAG,IAAI;IACnB;AACF,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|