@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.
Files changed (71) hide show
  1. package/README.md +270 -2
  2. package/dist/components/JsonLdEditor.d.ts +2 -0
  3. package/dist/components/JsonLdEditor.js +1184 -0
  4. package/dist/components/JsonLdEditor.js.map +1 -0
  5. package/dist/components/JsonLdTemplateRowLabel.d.ts +2 -0
  6. package/dist/components/JsonLdTemplateRowLabel.js +12 -0
  7. package/dist/components/JsonLdTemplateRowLabel.js.map +1 -0
  8. package/dist/components/MetaDescriptionComponent.d.ts +8 -0
  9. package/dist/components/MetaDescriptionComponent.js +101 -0
  10. package/dist/components/MetaDescriptionComponent.js.map +1 -0
  11. package/dist/components/MetaTitleComponent.d.ts +9 -0
  12. package/dist/components/MetaTitleComponent.js +193 -0
  13. package/dist/components/MetaTitleComponent.js.map +1 -0
  14. package/dist/components/OverviewComponent.d.ts +8 -0
  15. package/dist/components/OverviewComponent.js +64 -0
  16. package/dist/components/OverviewComponent.js.map +1 -0
  17. package/dist/components/PreviewComponent.d.ts +8 -0
  18. package/dist/components/PreviewComponent.js +51 -0
  19. package/dist/components/PreviewComponent.js.map +1 -0
  20. package/dist/exports/client.d.ts +6 -0
  21. package/dist/exports/client.js +8 -0
  22. package/dist/exports/client.js.map +1 -0
  23. package/dist/exports/next.d.ts +2 -0
  24. package/dist/exports/next.js +3 -0
  25. package/dist/exports/next.js.map +1 -0
  26. package/dist/exports/rsc.d.ts +1 -0
  27. package/dist/exports/rsc.js +5 -0
  28. package/dist/exports/rsc.js.map +1 -0
  29. package/dist/fields.d.ts +67 -0
  30. package/dist/fields.js +220 -0
  31. package/dist/fields.js.map +1 -0
  32. package/dist/global.d.ts +6 -0
  33. package/dist/global.js +93 -0
  34. package/dist/global.js.map +1 -0
  35. package/dist/helpers.d.ts +44 -0
  36. package/dist/helpers.js +23 -0
  37. package/dist/helpers.js.map +1 -0
  38. package/dist/helpers.test.d.ts +1 -0
  39. package/dist/helpers.test.js +234 -0
  40. package/dist/helpers.test.js.map +1 -0
  41. package/dist/hooks/autoAlternates.d.ts +18 -0
  42. package/dist/hooks/autoAlternates.js +63 -0
  43. package/dist/hooks/autoAlternates.js.map +1 -0
  44. package/dist/hooks/autoAlternates.test.d.ts +1 -0
  45. package/dist/hooks/autoAlternates.test.js +225 -0
  46. package/dist/hooks/autoAlternates.test.js.map +1 -0
  47. package/dist/hooks/generateMeta.d.ts +17 -0
  48. package/dist/hooks/generateMeta.js +58 -0
  49. package/dist/hooks/generateMeta.js.map +1 -0
  50. package/dist/hooks/generateMeta.test.d.ts +1 -0
  51. package/dist/hooks/generateMeta.test.js +132 -0
  52. package/dist/hooks/generateMeta.test.js.map +1 -0
  53. package/dist/hooks/ogImageGenerator.d.ts +19 -0
  54. package/dist/hooks/ogImageGenerator.js +96 -0
  55. package/dist/hooks/ogImageGenerator.js.map +1 -0
  56. package/dist/index.d.ts +87 -0
  57. package/dist/index.js +269 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/jsonld.d.ts +83 -0
  60. package/dist/jsonld.js +179 -0
  61. package/dist/jsonld.js.map +1 -0
  62. package/dist/jsonld.test.d.ts +1 -0
  63. package/dist/jsonld.test.js +214 -0
  64. package/dist/jsonld.test.js.map +1 -0
  65. package/dist/metadata.d.ts +53 -0
  66. package/dist/metadata.js +114 -0
  67. package/dist/metadata.js.map +1 -0
  68. package/dist/metadata.test.d.ts +1 -0
  69. package/dist/metadata.test.js +286 -0
  70. package/dist/metadata.test.js.map +1 -0
  71. package/package.json +100 -3
package/dist/index.js ADDED
@@ -0,0 +1,269 @@
1
+ import { MetaAlternatesField, MetaDescriptionField, MetaImageField, MetaJsonLdField, MetaNofollowField, MetaNoindexField, MetaPreviewField, MetaTitleField, MetaUrlField, OverviewField, structuredDataRow } from './fields.js';
2
+ import { getGlobalSeoGlobal } from './global.js';
3
+ import { buildAutoAlternatesHook } from './hooks/autoAlternates.js';
4
+ import { buildGenerateMetaHook } from './hooks/generateMeta.js';
5
+ import { buildOgImageHook } from './hooks/ogImageGenerator.js';
6
+ // ---------------------------------------------------------------------------
7
+ // Default JSON-LD templates seeded into global-seo on first run
8
+ // ---------------------------------------------------------------------------
9
+ const DEFAULT_JSON_LD_TEMPLATES = [
10
+ {
11
+ name: 'Web Page',
12
+ template: {
13
+ '@context': 'https://schema.org',
14
+ '@type': 'WebPage'
15
+ }
16
+ },
17
+ {
18
+ name: 'Article',
19
+ template: {
20
+ '@context': 'https://schema.org',
21
+ '@type': 'Article',
22
+ headline: ''
23
+ }
24
+ },
25
+ {
26
+ name: 'Product',
27
+ template: {
28
+ '@context': 'https://schema.org',
29
+ '@type': 'Product',
30
+ name: ''
31
+ }
32
+ },
33
+ {
34
+ name: 'Organization',
35
+ template: {
36
+ '@context': 'https://schema.org',
37
+ '@type': 'Organization',
38
+ name: ''
39
+ }
40
+ },
41
+ {
42
+ name: 'Breadcrumb Trail',
43
+ template: {
44
+ '@context': 'https://schema.org',
45
+ '@type': 'BreadcrumbList',
46
+ itemListElement: [
47
+ {
48
+ '@type': 'ListItem',
49
+ item: '',
50
+ name: 'Home',
51
+ position: 1
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ ];
57
+ export { resolveMeta } from './helpers.js';
58
+ export { articleJsonLd, breadcrumbJsonLd, buildJsonLd, organizationJsonLd, productJsonLd, webPageJsonLd } from './jsonld.js';
59
+ export { toNextMetadata } from './metadata.js';
60
+ export { MetaAlternatesField, MetaDescriptionField, MetaImageField, MetaJsonLdField, MetaNofollowField, MetaNoindexField, MetaPreviewField, MetaTitleField, MetaUrlField, OverviewField, structuredDataRow };
61
+ export const seoPlugin = (pluginOptions)=>(incomingConfig)=>{
62
+ const config = {
63
+ ...incomingConfig
64
+ };
65
+ const mediaCollection = pluginOptions.mediaCollection ?? [
66
+ 'media'
67
+ ];
68
+ // Register the global-seo global
69
+ config.globals = [
70
+ ...config.globals || [],
71
+ getGlobalSeoGlobal({
72
+ mediaCollection
73
+ })
74
+ ];
75
+ // Inject meta group + hooks into configured collections
76
+ if (pluginOptions.collections) {
77
+ config.collections = (config.collections || []).map((collection)=>{
78
+ if (!pluginOptions.collections[collection.slug]) {
79
+ return collection;
80
+ }
81
+ const collectionSlug = collection.slug;
82
+ const generateMetaHook = buildGenerateMetaHook({
83
+ collectionSlug,
84
+ generateTitle: pluginOptions.generateTitle,
85
+ generateURL: pluginOptions.generateURL
86
+ });
87
+ const autoAlternatesHook = buildAutoAlternatesHook({
88
+ collectionSlug,
89
+ generateAlternateURL: pluginOptions.generateAlternateURL,
90
+ locales: pluginOptions.locales ?? []
91
+ });
92
+ const ogImageHook = buildOgImageHook({
93
+ collectionSlug,
94
+ generateOgImage: pluginOptions.generateOgImage,
95
+ mediaCollection: mediaCollection[0] ?? 'media'
96
+ });
97
+ const endpoints = Array.isArray(collection.endpoints) ? [
98
+ ...collection.endpoints
99
+ ] : [];
100
+ // Always register the generate-title endpoint — uses user's generateTitle if provided,
101
+ // otherwise falls back to: doc.title + " | " + global-seo siteName
102
+ endpoints.push({
103
+ handler: async (req)=>{
104
+ try {
105
+ const data = await req.json?.().catch(()=>({})) ?? {};
106
+ let title = null;
107
+ if (pluginOptions.generateTitle) {
108
+ title = await pluginOptions.generateTitle({
109
+ collectionSlug,
110
+ data,
111
+ req
112
+ });
113
+ } else {
114
+ // Built-in default: "Doc Title | Site Name"
115
+ const docTitle = typeof data.title === 'string' ? data.title : null;
116
+ let siteName = null;
117
+ try {
118
+ const globalSeo = await req.payload.findGlobal({
119
+ slug: 'global-seo'
120
+ });
121
+ siteName = typeof globalSeo.siteName === 'string' ? globalSeo.siteName : null;
122
+ } catch {
123
+ // global-seo not found — skip site name
124
+ }
125
+ if (docTitle && siteName) title = `${docTitle} | ${siteName}`;
126
+ else if (docTitle) title = docTitle;
127
+ }
128
+ return Response.json({
129
+ title
130
+ });
131
+ } catch {
132
+ return Response.json({
133
+ title: null
134
+ });
135
+ }
136
+ },
137
+ method: 'post',
138
+ path: '/generate-title'
139
+ });
140
+ const seoFields = [
141
+ OverviewField({
142
+ descriptionPath: 'meta.metaDescription',
143
+ imagePath: 'meta.metaImage',
144
+ titlePath: 'meta.metaTitle'
145
+ }),
146
+ MetaTitleField({
147
+ hasGenerateFn: true
148
+ }),
149
+ MetaUrlField({}),
150
+ MetaImageField({
151
+ relationTo: mediaCollection[0] ?? 'media'
152
+ }),
153
+ MetaDescriptionField({}),
154
+ MetaNoindexField({}),
155
+ MetaNofollowField({}),
156
+ MetaAlternatesField({}),
157
+ structuredDataRow,
158
+ MetaPreviewField({
159
+ descriptionPath: 'meta.metaDescription',
160
+ titlePath: 'meta.metaTitle'
161
+ })
162
+ ];
163
+ let fields;
164
+ if (pluginOptions.tabbedUI) {
165
+ const firstField = collection.fields[0];
166
+ const firstIsTabsField = firstField?.type === 'tabs';
167
+ // Named tab so data saves under meta.* — consistent with hooks and resolveMeta
168
+ const seoTab = {
169
+ name: 'meta',
170
+ fields: seoFields,
171
+ label: 'SEO'
172
+ };
173
+ if (firstIsTabsField) {
174
+ // Append SEO tab to the existing tabs field
175
+ const existingTabs = firstField;
176
+ fields = [
177
+ {
178
+ ...existingTabs,
179
+ tabs: [
180
+ ...existingTabs.tabs,
181
+ seoTab
182
+ ]
183
+ },
184
+ ...collection.fields.slice(1)
185
+ ];
186
+ } else {
187
+ // Wrap all existing fields in a "Content" tab, add SEO tab
188
+ fields = [
189
+ {
190
+ type: 'tabs',
191
+ tabs: [
192
+ {
193
+ fields: collection.fields,
194
+ label: 'Content'
195
+ },
196
+ seoTab
197
+ ]
198
+ }
199
+ ];
200
+ }
201
+ } else {
202
+ // Default: append a meta group to the sidebar
203
+ fields = [
204
+ ...collection.fields,
205
+ {
206
+ name: 'meta',
207
+ type: 'group',
208
+ admin: {
209
+ position: 'sidebar'
210
+ },
211
+ fields: seoFields,
212
+ label: 'SEO'
213
+ }
214
+ ];
215
+ }
216
+ return {
217
+ ...collection,
218
+ endpoints,
219
+ fields,
220
+ hooks: {
221
+ ...collection.hooks,
222
+ afterChange: [
223
+ ...collection.hooks?.afterChange ?? [],
224
+ ogImageHook
225
+ ],
226
+ afterRead: [
227
+ ...collection.hooks?.afterRead ?? [],
228
+ autoAlternatesHook
229
+ ],
230
+ beforeChange: [
231
+ ...collection.hooks?.beforeChange ?? [],
232
+ generateMetaHook
233
+ ]
234
+ }
235
+ };
236
+ });
237
+ }
238
+ // Keep schema consistent even when disabled (important for migrations)
239
+ if (pluginOptions.disabled) {
240
+ return config;
241
+ }
242
+ // Seed default JSON-LD templates into global-seo on first run
243
+ const userOnInit = config.onInit;
244
+ config.onInit = async (payload)=>{
245
+ // Run the user's own onInit first
246
+ if (userOnInit) await userOnInit(payload);
247
+ try {
248
+ const existing = await payload.findGlobal({
249
+ slug: 'global-seo'
250
+ });
251
+ const templates = existing.jsonLdTemplates;
252
+ // Only seed when no templates have been saved yet
253
+ if (!templates || templates.length === 0) {
254
+ await payload.updateGlobal({
255
+ slug: 'global-seo',
256
+ data: {
257
+ jsonLdTemplates: DEFAULT_JSON_LD_TEMPLATES
258
+ }
259
+ });
260
+ }
261
+ } catch {
262
+ // global-seo not available yet (e.g. fresh DB before migrations) — skip silently
263
+ }
264
+ };
265
+ return config;
266
+ };
267
+ /** @deprecated Renamed to `seoPlugin`. */ export const advancedSeoPlugin = seoPlugin;
268
+
269
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionSlug, Config, Field, TabsField } from 'payload';\n\nimport {\n MetaAlternatesField,\n MetaDescriptionField,\n MetaImageField,\n MetaJsonLdField,\n MetaNofollowField,\n MetaNoindexField,\n MetaPreviewField,\n MetaTitleField,\n MetaUrlField,\n OverviewField,\n structuredDataRow,\n} from './fields.js';\nimport { getGlobalSeoGlobal } from './global.js';\nimport { buildAutoAlternatesHook } from './hooks/autoAlternates.js';\nimport { buildGenerateMetaHook } from './hooks/generateMeta.js';\nimport { buildOgImageHook } from './hooks/ogImageGenerator.js';\n\n// ---------------------------------------------------------------------------\n// Default JSON-LD templates seeded into global-seo on first run\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_JSON_LD_TEMPLATES = [\n {\n name: 'Web Page',\n template: {\n '@context': 'https://schema.org',\n '@type': 'WebPage',\n },\n },\n {\n name: 'Article',\n template: {\n '@context': 'https://schema.org',\n '@type': 'Article',\n headline: '',\n },\n },\n {\n name: 'Product',\n template: {\n '@context': 'https://schema.org',\n '@type': 'Product',\n name: '',\n },\n },\n {\n name: 'Organization',\n template: {\n '@context': 'https://schema.org',\n '@type': 'Organization',\n name: '',\n },\n },\n {\n name: 'Breadcrumb Trail',\n template: {\n '@context': 'https://schema.org',\n '@type': 'BreadcrumbList',\n itemListElement: [\n { '@type': 'ListItem', item: '', name: 'Home', position: 1 },\n ],\n },\n },\n];\n\nexport type GenerateAlternateURLArgs = {\n collectionSlug: string;\n doc: Record<string, unknown>;\n locale: string;\n};\n\nexport type GenerateOgImageArgs = {\n collectionSlug: string;\n doc: Record<string, unknown>;\n};\n\nexport type GenerateTitleArgs = {\n collectionSlug: string;\n data: Record<string, unknown>;\n req: import('payload').PayloadRequest;\n};\n\nexport type GenerateURLArgs = {\n collectionSlug: string;\n data: Record<string, unknown>;\n req: import('payload').PayloadRequest;\n};\n\nexport type SeoPluginConfig = {\n /**\n * Collections to inject the `meta` SEO group into.\n * Set a collection slug to `true` to enable.\n */\n collections?: Partial<Record<CollectionSlug, true>>;\n /**\n * Disable the plugin without uninstalling it.\n * Keeps DB schema consistent for migrations.\n * @default false\n */\n disabled?: boolean;\n /**\n * Build the URL for an auto-generated alternate.\n * Called once per locale for each document on read.\n * Return null to skip a locale.\n */\n generateAlternateURL?: (\n args: GenerateAlternateURLArgs\n ) => null | Promise<null | string> | string;\n /**\n * Called when the OG image generator is enabled and a document has no\n * meta.image set. Return a Buffer (PNG/JPEG) to save as the OG image,\n * or null to skip generation for this document.\n */\n generateOgImage?: (\n args: GenerateOgImageArgs\n ) => Buffer | null | Promise<Buffer | null>;\n /**\n * Auto-populate meta.title on save when the field is empty.\n * Return a string to set the title, or null to skip.\n */\n generateTitle?: (\n args: GenerateTitleArgs\n ) => string | null | Promise<string | null>;\n /**\n * Auto-populate meta.url (canonical URL) on save when the field is empty.\n * Return a string to set the URL, or null to skip.\n */\n generateURL?: (\n args: GenerateURLArgs\n ) => string | null | Promise<string | null>;\n /**\n * BCP 47 locale codes used when auto-generating hreflang alternates.\n * Required for auto-alternates to work.\n * @example ['en', 'fr', 'de']\n */\n locales?: string[];\n /**\n * Media collection slug(s) used for the image picker.\n * @default ['media']\n */\n mediaCollection?: string[];\n /**\n * When true, injects the SEO fields into a dedicated \"SEO\" tab using Payload's Tabs Field.\n * If the collection's first field is already a `tabs` field, the SEO tab is appended to it.\n * Otherwise a new tabs field is created with a \"Content\" tab wrapping existing fields and\n * an \"SEO\" tab containing the meta fields.\n * @default false\n */\n tabbedUI?: boolean;\n};\n\nexport type {\n Alternate,\n DocWithMeta,\n GlobalSeoDefaults,\n ResolvedMeta,\n} from './helpers.js';\nexport { resolveMeta } from './helpers.js';\nexport type {\n ArticleJsonLdArgs,\n BreadcrumbItem,\n JsonLdBase,\n OrganizationJsonLdArgs,\n ProductJsonLdArgs,\n WebPageJsonLdArgs,\n} from './jsonld.js';\nexport {\n articleJsonLd,\n breadcrumbJsonLd,\n buildJsonLd,\n organizationJsonLd,\n productJsonLd,\n webPageJsonLd,\n} from './jsonld.js';\nexport type { MetadataResult, ToNextMetadataOptions } from './metadata.js';\nexport { toNextMetadata } from './metadata.js';\nexport {\n MetaAlternatesField,\n MetaDescriptionField,\n MetaImageField,\n MetaJsonLdField,\n MetaNofollowField,\n MetaNoindexField,\n MetaPreviewField,\n MetaTitleField,\n MetaUrlField,\n OverviewField,\n structuredDataRow,\n};\n\nexport const seoPlugin =\n (pluginOptions: SeoPluginConfig) =>\n (incomingConfig: Config): Config => {\n const config = { ...incomingConfig };\n const mediaCollection = pluginOptions.mediaCollection ?? ['media'];\n\n // Register the global-seo global\n config.globals = [\n ...(config.globals || []),\n getGlobalSeoGlobal({ mediaCollection }),\n ];\n\n // Inject meta group + hooks into configured collections\n if (pluginOptions.collections) {\n config.collections = (config.collections || []).map(collection => {\n if (!pluginOptions.collections![collection.slug]) {\n return collection;\n }\n\n const collectionSlug = collection.slug;\n\n const generateMetaHook = buildGenerateMetaHook({\n collectionSlug,\n generateTitle: pluginOptions.generateTitle,\n generateURL: pluginOptions.generateURL,\n });\n\n const autoAlternatesHook = buildAutoAlternatesHook({\n collectionSlug,\n generateAlternateURL: pluginOptions.generateAlternateURL,\n locales: pluginOptions.locales ?? [],\n });\n\n const ogImageHook = buildOgImageHook({\n collectionSlug,\n generateOgImage: pluginOptions.generateOgImage,\n mediaCollection: mediaCollection[0] ?? 'media',\n });\n\n const endpoints = Array.isArray(collection.endpoints)\n ? [...collection.endpoints]\n : [];\n\n // Always register the generate-title endpoint — uses user's generateTitle if provided,\n // otherwise falls back to: doc.title + \" | \" + global-seo siteName\n endpoints.push({\n handler: async (req: import('payload').PayloadRequest) => {\n try {\n const data = ((await req.json?.().catch(() => ({}))) ??\n {}) as Record<string, unknown>;\n\n let title: null | string = null;\n\n if (pluginOptions.generateTitle) {\n title = await pluginOptions.generateTitle({\n collectionSlug,\n data,\n req,\n });\n } else {\n // Built-in default: \"Doc Title | Site Name\"\n const docTitle =\n typeof data.title === 'string' ? data.title : null;\n\n let siteName: null | string = null;\n try {\n const globalSeo = await req.payload.findGlobal({\n slug: 'global-seo',\n });\n siteName =\n typeof (globalSeo as Record<string, unknown>).siteName ===\n 'string'\n ? ((globalSeo as Record<string, unknown>)\n .siteName as string)\n : null;\n } catch {\n // global-seo not found — skip site name\n }\n\n if (docTitle && siteName) title = `${docTitle} | ${siteName}`;\n else if (docTitle) title = docTitle;\n }\n\n return Response.json({ title });\n } catch {\n return Response.json({ title: null });\n }\n },\n method: 'post',\n path: '/generate-title',\n });\n\n const seoFields: Field[] = [\n OverviewField({\n descriptionPath: 'meta.metaDescription',\n imagePath: 'meta.metaImage',\n titlePath: 'meta.metaTitle',\n }),\n MetaTitleField({ hasGenerateFn: true }),\n MetaUrlField({}),\n MetaImageField({ relationTo: mediaCollection[0] ?? 'media' }),\n MetaDescriptionField({}),\n MetaNoindexField({}),\n MetaNofollowField({}),\n MetaAlternatesField({}),\n structuredDataRow,\n MetaPreviewField({\n descriptionPath: 'meta.metaDescription',\n titlePath: 'meta.metaTitle',\n }),\n ];\n\n let fields: Field[];\n\n if (pluginOptions.tabbedUI) {\n const firstField = collection.fields[0];\n const firstIsTabsField = firstField?.type === 'tabs';\n\n // Named tab so data saves under meta.* — consistent with hooks and resolveMeta\n const seoTab = { name: 'meta', fields: seoFields, label: 'SEO' };\n\n if (firstIsTabsField) {\n // Append SEO tab to the existing tabs field\n const existingTabs = firstField as TabsField;\n fields = [\n {\n ...existingTabs,\n tabs: [...existingTabs.tabs, seoTab],\n },\n ...collection.fields.slice(1),\n ];\n } else {\n // Wrap all existing fields in a \"Content\" tab, add SEO tab\n fields = [\n {\n type: 'tabs' as const,\n tabs: [\n { fields: collection.fields as Field[], label: 'Content' },\n seoTab,\n ],\n },\n ];\n }\n } else {\n // Default: append a meta group to the sidebar\n fields = [\n ...collection.fields,\n {\n name: 'meta',\n type: 'group' as const,\n admin: { position: 'sidebar' as const },\n fields: seoFields,\n label: 'SEO',\n },\n ];\n }\n\n return {\n ...collection,\n endpoints,\n fields,\n hooks: {\n ...collection.hooks,\n afterChange: [\n ...(collection.hooks?.afterChange ?? []),\n ogImageHook,\n ],\n afterRead: [\n ...(collection.hooks?.afterRead ?? []),\n autoAlternatesHook,\n ],\n beforeChange: [\n ...(collection.hooks?.beforeChange ?? []),\n generateMetaHook,\n ],\n },\n };\n });\n }\n\n // Keep schema consistent even when disabled (important for migrations)\n if (pluginOptions.disabled) {\n return config;\n }\n\n // Seed default JSON-LD templates into global-seo on first run\n const userOnInit = config.onInit;\n config.onInit = async payload => {\n // Run the user's own onInit first\n if (userOnInit) await userOnInit(payload);\n\n try {\n const existing = await payload.findGlobal({ slug: 'global-seo' });\n const templates = (existing as Record<string, unknown>)\n .jsonLdTemplates as unknown[] | undefined;\n\n // Only seed when no templates have been saved yet\n if (!templates || templates.length === 0) {\n await payload.updateGlobal({\n slug: 'global-seo',\n data: {\n jsonLdTemplates: DEFAULT_JSON_LD_TEMPLATES,\n },\n });\n }\n } catch {\n // global-seo not available yet (e.g. fresh DB before migrations) — skip silently\n }\n };\n\n return config;\n };\n\n/** @deprecated Renamed to `seoPlugin`. */\nexport const advancedSeoPlugin = seoPlugin;\n/** @deprecated Renamed to `SeoPluginConfig`. */\nexport type AdvancedSeoPluginConfig = SeoPluginConfig;\n"],"names":["MetaAlternatesField","MetaDescriptionField","MetaImageField","MetaJsonLdField","MetaNofollowField","MetaNoindexField","MetaPreviewField","MetaTitleField","MetaUrlField","OverviewField","structuredDataRow","getGlobalSeoGlobal","buildAutoAlternatesHook","buildGenerateMetaHook","buildOgImageHook","DEFAULT_JSON_LD_TEMPLATES","name","template","headline","itemListElement","item","position","resolveMeta","articleJsonLd","breadcrumbJsonLd","buildJsonLd","organizationJsonLd","productJsonLd","webPageJsonLd","toNextMetadata","seoPlugin","pluginOptions","incomingConfig","config","mediaCollection","globals","collections","map","collection","slug","collectionSlug","generateMetaHook","generateTitle","generateURL","autoAlternatesHook","generateAlternateURL","locales","ogImageHook","generateOgImage","endpoints","Array","isArray","push","handler","req","data","json","catch","title","docTitle","siteName","globalSeo","payload","findGlobal","Response","method","path","seoFields","descriptionPath","imagePath","titlePath","hasGenerateFn","relationTo","fields","tabbedUI","firstField","firstIsTabsField","type","seoTab","label","existingTabs","tabs","slice","admin","hooks","afterChange","afterRead","beforeChange","disabled","userOnInit","onInit","existing","templates","jsonLdTemplates","length","updateGlobal","advancedSeoPlugin"],"mappings":"AAEA,SACEA,mBAAmB,EACnBC,oBAAoB,EACpBC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EACjB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zBxD,MAAM;wBACNgB,MAAM;4BACJsC,iBAAiB9E;wBACnB;oBACF;gBACF;YACF,EAAE,OAAM;YACN,iFAAiF;YACnF;QACF;QAEA,OAAOkB;IACT,EAAE;AAEJ,wCAAwC,GACxC,OAAO,MAAM+D,oBAAoBlE,UAAU"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * JSON-LD template builders for common schema.org types.
3
+ *
4
+ * Each builder returns a fully-formed JSON-LD object that can be:
5
+ * - Stored directly in the `meta.jsonLd` field on a document
6
+ * - Used as a starting template in the Global SEO jsonLdTemplates array
7
+ * - Merged with doc-specific data via `buildJsonLd`
8
+ *
9
+ * All fields are optional — only include what you have data for.
10
+ * See https://schema.org for the full specification of each type.
11
+ */
12
+ export type JsonLdBase = {
13
+ '@context': 'https://schema.org';
14
+ '@type': string;
15
+ [key: string]: unknown;
16
+ };
17
+ export type WebPageJsonLdArgs = {
18
+ breadcrumb?: string;
19
+ dateModified?: string;
20
+ datePublished?: string;
21
+ description?: string;
22
+ image?: string;
23
+ name?: string;
24
+ url?: string;
25
+ };
26
+ export declare const webPageJsonLd: (args?: WebPageJsonLdArgs) => JsonLdBase;
27
+ export type ArticleJsonLdArgs = {
28
+ articleBody?: string;
29
+ author?: string | {
30
+ name: string;
31
+ url?: string;
32
+ };
33
+ dateModified?: string;
34
+ datePublished?: string;
35
+ description?: string;
36
+ headline?: string;
37
+ image?: string;
38
+ publisher?: {
39
+ logo?: string;
40
+ name: string;
41
+ };
42
+ url?: string;
43
+ };
44
+ export declare const articleJsonLd: (args?: ArticleJsonLdArgs) => JsonLdBase;
45
+ export type ProductJsonLdArgs = {
46
+ brand?: string;
47
+ description?: string;
48
+ image?: string;
49
+ name?: string;
50
+ offers?: {
51
+ availability?: string;
52
+ currency?: string;
53
+ price?: number | string;
54
+ url?: string;
55
+ };
56
+ sku?: string;
57
+ url?: string;
58
+ };
59
+ export declare const productJsonLd: (args?: ProductJsonLdArgs) => JsonLdBase;
60
+ export type OrganizationJsonLdArgs = {
61
+ description?: string;
62
+ email?: string;
63
+ logo?: string;
64
+ name?: string;
65
+ sameAs?: string[];
66
+ telephone?: string;
67
+ url?: string;
68
+ };
69
+ export declare const organizationJsonLd: (args?: OrganizationJsonLdArgs) => JsonLdBase;
70
+ export type BreadcrumbItem = {
71
+ id: string;
72
+ name: string;
73
+ };
74
+ export declare const breadcrumbJsonLd: (items: BreadcrumbItem[]) => JsonLdBase;
75
+ /**
76
+ * Merges a base JSON-LD template (e.g. from globals) with doc-specific
77
+ * overrides. Doc-level values take precedence over the template.
78
+ *
79
+ * @example
80
+ * const base = articleJsonLd({ headline: 'Default headline' })
81
+ * const merged = buildJsonLd(base, { headline: doc.meta.title, url: doc.url })
82
+ */
83
+ export declare const buildJsonLd: (base: JsonLdBase, overrides?: Record<string, unknown>) => JsonLdBase;
package/dist/jsonld.js ADDED
@@ -0,0 +1,179 @@
1
+ /**
2
+ * JSON-LD template builders for common schema.org types.
3
+ *
4
+ * Each builder returns a fully-formed JSON-LD object that can be:
5
+ * - Stored directly in the `meta.jsonLd` field on a document
6
+ * - Used as a starting template in the Global SEO jsonLdTemplates array
7
+ * - Merged with doc-specific data via `buildJsonLd`
8
+ *
9
+ * All fields are optional — only include what you have data for.
10
+ * See https://schema.org for the full specification of each type.
11
+ */ export const webPageJsonLd = (args = {})=>({
12
+ '@context': 'https://schema.org',
13
+ '@type': 'WebPage',
14
+ ...args.name && {
15
+ name: args.name
16
+ },
17
+ ...args.url && {
18
+ url: args.url
19
+ },
20
+ ...args.description && {
21
+ description: args.description
22
+ },
23
+ ...args.image && {
24
+ image: args.image
25
+ },
26
+ ...args.datePublished && {
27
+ datePublished: args.datePublished
28
+ },
29
+ ...args.dateModified && {
30
+ dateModified: args.dateModified
31
+ },
32
+ ...args.breadcrumb && {
33
+ breadcrumb: args.breadcrumb
34
+ }
35
+ });
36
+ export const articleJsonLd = (args = {})=>({
37
+ '@context': 'https://schema.org',
38
+ '@type': 'Article',
39
+ ...args.headline && {
40
+ headline: args.headline
41
+ },
42
+ ...args.url && {
43
+ url: args.url
44
+ },
45
+ ...args.description && {
46
+ description: args.description
47
+ },
48
+ ...args.image && {
49
+ image: args.image
50
+ },
51
+ ...args.datePublished && {
52
+ datePublished: args.datePublished
53
+ },
54
+ ...args.dateModified && {
55
+ dateModified: args.dateModified
56
+ },
57
+ ...args.articleBody && {
58
+ articleBody: args.articleBody
59
+ },
60
+ ...args.author && {
61
+ author: typeof args.author === 'string' ? {
62
+ '@type': 'Person',
63
+ name: args.author
64
+ } : {
65
+ '@type': 'Person',
66
+ ...args.author
67
+ }
68
+ },
69
+ ...args.publisher && {
70
+ publisher: {
71
+ '@type': 'Organization',
72
+ name: args.publisher.name,
73
+ ...args.publisher.logo && {
74
+ logo: {
75
+ '@type': 'ImageObject',
76
+ url: args.publisher.logo
77
+ }
78
+ }
79
+ }
80
+ }
81
+ });
82
+ export const productJsonLd = (args = {})=>({
83
+ '@context': 'https://schema.org',
84
+ '@type': 'Product',
85
+ ...args.name && {
86
+ name: args.name
87
+ },
88
+ ...args.url && {
89
+ url: args.url
90
+ },
91
+ ...args.description && {
92
+ description: args.description
93
+ },
94
+ ...args.image && {
95
+ image: args.image
96
+ },
97
+ ...args.sku && {
98
+ sku: args.sku
99
+ },
100
+ ...args.brand && {
101
+ brand: {
102
+ '@type': 'Brand',
103
+ name: args.brand
104
+ }
105
+ },
106
+ ...args.offers && {
107
+ offers: {
108
+ '@type': 'Offer',
109
+ ...args.offers.price !== undefined && {
110
+ price: args.offers.price
111
+ },
112
+ ...args.offers.currency && {
113
+ priceCurrency: args.offers.currency
114
+ },
115
+ ...args.offers.availability && {
116
+ availability: args.offers.availability
117
+ },
118
+ ...args.offers.url && {
119
+ url: args.offers.url
120
+ }
121
+ }
122
+ }
123
+ });
124
+ export const organizationJsonLd = (args = {})=>({
125
+ '@context': 'https://schema.org',
126
+ '@type': 'Organization',
127
+ ...args.name && {
128
+ name: args.name
129
+ },
130
+ ...args.url && {
131
+ url: args.url
132
+ },
133
+ ...args.description && {
134
+ description: args.description
135
+ },
136
+ ...args.email && {
137
+ email: args.email
138
+ },
139
+ ...args.telephone && {
140
+ telephone: args.telephone
141
+ },
142
+ ...args.logo && {
143
+ logo: {
144
+ '@type': 'ImageObject',
145
+ url: args.logo
146
+ }
147
+ },
148
+ ...args.sameAs && args.sameAs.length > 0 && {
149
+ sameAs: args.sameAs
150
+ }
151
+ });
152
+ export const breadcrumbJsonLd = (items)=>({
153
+ '@context': 'https://schema.org',
154
+ '@type': 'BreadcrumbList',
155
+ itemListElement: items.map((item, index)=>({
156
+ '@type': 'ListItem',
157
+ position: index + 1,
158
+ name: item.name,
159
+ item: item.id
160
+ }))
161
+ });
162
+ // ---------------------------------------------------------------------------
163
+ // Merge utility
164
+ // ---------------------------------------------------------------------------
165
+ /**
166
+ * Merges a base JSON-LD template (e.g. from globals) with doc-specific
167
+ * overrides. Doc-level values take precedence over the template.
168
+ *
169
+ * @example
170
+ * const base = articleJsonLd({ headline: 'Default headline' })
171
+ * const merged = buildJsonLd(base, { headline: doc.meta.title, url: doc.url })
172
+ */ export const buildJsonLd = (base, overrides = {})=>({
173
+ ...base,
174
+ ...overrides,
175
+ '@context': 'https://schema.org',
176
+ '@type': base['@type']
177
+ });
178
+
179
+ //# sourceMappingURL=jsonld.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/jsonld.ts"],"sourcesContent":["/**\n * JSON-LD template builders for common schema.org types.\n *\n * Each builder returns a fully-formed JSON-LD object that can be:\n * - Stored directly in the `meta.jsonLd` field on a document\n * - Used as a starting template in the Global SEO jsonLdTemplates array\n * - Merged with doc-specific data via `buildJsonLd`\n *\n * All fields are optional — only include what you have data for.\n * See https://schema.org for the full specification of each type.\n */\n\nexport type JsonLdBase = {\n '@context': 'https://schema.org';\n '@type': string;\n [key: string]: unknown;\n};\n\n// ---------------------------------------------------------------------------\n// WebPage\n// ---------------------------------------------------------------------------\n\nexport type WebPageJsonLdArgs = {\n breadcrumb?: string;\n dateModified?: string;\n datePublished?: string;\n description?: string;\n image?: string;\n name?: string;\n url?: string;\n};\n\nexport const webPageJsonLd = (args: WebPageJsonLdArgs = {}): JsonLdBase => ({\n '@context': 'https://schema.org',\n '@type': 'WebPage',\n ...(args.name && { name: args.name }),\n ...(args.url && { url: args.url }),\n ...(args.description && { description: args.description }),\n ...(args.image && { image: args.image }),\n ...(args.datePublished && { datePublished: args.datePublished }),\n ...(args.dateModified && { dateModified: args.dateModified }),\n ...(args.breadcrumb && { breadcrumb: args.breadcrumb }),\n});\n\n// ---------------------------------------------------------------------------\n// Article\n// ---------------------------------------------------------------------------\n\nexport type ArticleJsonLdArgs = {\n articleBody?: string;\n author?: string | { name: string; url?: string };\n dateModified?: string;\n datePublished?: string;\n description?: string;\n headline?: string;\n image?: string;\n publisher?: { logo?: string; name: string };\n url?: string;\n};\n\nexport const articleJsonLd = (args: ArticleJsonLdArgs = {}): JsonLdBase => ({\n '@context': 'https://schema.org',\n '@type': 'Article',\n ...(args.headline && { headline: args.headline }),\n ...(args.url && { url: args.url }),\n ...(args.description && { description: args.description }),\n ...(args.image && { image: args.image }),\n ...(args.datePublished && { datePublished: args.datePublished }),\n ...(args.dateModified && { dateModified: args.dateModified }),\n ...(args.articleBody && { articleBody: args.articleBody }),\n ...(args.author && {\n author:\n typeof args.author === 'string'\n ? { '@type': 'Person', name: args.author }\n : { '@type': 'Person', ...args.author },\n }),\n ...(args.publisher && {\n publisher: {\n '@type': 'Organization',\n name: args.publisher.name,\n ...(args.publisher.logo && {\n logo: { '@type': 'ImageObject', url: args.publisher.logo },\n }),\n },\n }),\n});\n\n// ---------------------------------------------------------------------------\n// Product\n// ---------------------------------------------------------------------------\n\nexport type ProductJsonLdArgs = {\n brand?: string;\n description?: string;\n image?: string;\n name?: string;\n offers?: {\n availability?: string;\n currency?: string;\n price?: number | string;\n url?: string;\n };\n sku?: string;\n url?: string;\n};\n\nexport const productJsonLd = (args: ProductJsonLdArgs = {}): JsonLdBase => ({\n '@context': 'https://schema.org',\n '@type': 'Product',\n ...(args.name && { name: args.name }),\n ...(args.url && { url: args.url }),\n ...(args.description && { description: args.description }),\n ...(args.image && { image: args.image }),\n ...(args.sku && { sku: args.sku }),\n ...(args.brand && { brand: { '@type': 'Brand', name: args.brand } }),\n ...(args.offers && {\n offers: {\n '@type': 'Offer',\n ...(args.offers.price !== undefined && { price: args.offers.price }),\n ...(args.offers.currency && { priceCurrency: args.offers.currency }),\n ...(args.offers.availability && {\n availability: args.offers.availability,\n }),\n ...(args.offers.url && { url: args.offers.url }),\n },\n }),\n});\n\n// ---------------------------------------------------------------------------\n// Organization\n// ---------------------------------------------------------------------------\n\nexport type OrganizationJsonLdArgs = {\n description?: string;\n email?: string;\n logo?: string;\n name?: string;\n sameAs?: string[];\n telephone?: string;\n url?: string;\n};\n\nexport const organizationJsonLd = (\n args: OrganizationJsonLdArgs = {}\n): JsonLdBase => ({\n '@context': 'https://schema.org',\n '@type': 'Organization',\n ...(args.name && { name: args.name }),\n ...(args.url && { url: args.url }),\n ...(args.description && { description: args.description }),\n ...(args.email && { email: args.email }),\n ...(args.telephone && { telephone: args.telephone }),\n ...(args.logo && { logo: { '@type': 'ImageObject', url: args.logo } }),\n ...(args.sameAs && args.sameAs.length > 0 && { sameAs: args.sameAs }),\n});\n\n// ---------------------------------------------------------------------------\n// BreadcrumbList\n// ---------------------------------------------------------------------------\n\nexport type BreadcrumbItem = {\n id: string;\n name: string;\n};\n\nexport const breadcrumbJsonLd = (items: BreadcrumbItem[]): JsonLdBase => ({\n '@context': 'https://schema.org',\n '@type': 'BreadcrumbList',\n itemListElement: items.map((item, index) => ({\n '@type': 'ListItem',\n position: index + 1,\n name: item.name,\n item: item.id,\n })),\n});\n\n// ---------------------------------------------------------------------------\n// Merge utility\n// ---------------------------------------------------------------------------\n\n/**\n * Merges a base JSON-LD template (e.g. from globals) with doc-specific\n * overrides. Doc-level values take precedence over the template.\n *\n * @example\n * const base = articleJsonLd({ headline: 'Default headline' })\n * const merged = buildJsonLd(base, { headline: doc.meta.title, url: doc.url })\n */\nexport const buildJsonLd = (\n base: JsonLdBase,\n overrides: Record<string, unknown> = {}\n): JsonLdBase => ({\n ...base,\n ...overrides,\n '@context': 'https://schema.org',\n '@type': base['@type'],\n});\n"],"names":["webPageJsonLd","args","name","url","description","image","datePublished","dateModified","breadcrumb","articleJsonLd","headline","articleBody","author","publisher","logo","productJsonLd","sku","brand","offers","price","undefined","currency","priceCurrency","availability","organizationJsonLd","email","telephone","sameAs","length","breadcrumbJsonLd","items","itemListElement","map","item","index","position","id","buildJsonLd","base","overrides"],"mappings":"AAAA;;;;;;;;;;CAUC,GAsBD,OAAO,MAAMA,gBAAgB,CAACC,OAA0B,CAAC,CAAC,GAAkB,CAAA;QAC1E,YAAY;QACZ,SAAS;QACT,GAAIA,KAAKC,IAAI,IAAI;YAAEA,MAAMD,KAAKC,IAAI;QAAC,CAAC;QACpC,GAAID,KAAKE,GAAG,IAAI;YAAEA,KAAKF,KAAKE,GAAG;QAAC,CAAC;QACjC,GAAIF,KAAKG,WAAW,IAAI;YAAEA,aAAaH,KAAKG,WAAW;QAAC,CAAC;QACzD,GAAIH,KAAKI,KAAK,IAAI;YAAEA,OAAOJ,KAAKI,KAAK;QAAC,CAAC;QACvC,GAAIJ,KAAKK,aAAa,IAAI;YAAEA,eAAeL,KAAKK,aAAa;QAAC,CAAC;QAC/D,GAAIL,KAAKM,YAAY,IAAI;YAAEA,cAAcN,KAAKM,YAAY;QAAC,CAAC;QAC5D,GAAIN,KAAKO,UAAU,IAAI;YAAEA,YAAYP,KAAKO,UAAU;QAAC,CAAC;IACxD,CAAA,EAAG;AAkBH,OAAO,MAAMC,gBAAgB,CAACR,OAA0B,CAAC,CAAC,GAAkB,CAAA;QAC1E,YAAY;QACZ,SAAS;QACT,GAAIA,KAAKS,QAAQ,IAAI;YAAEA,UAAUT,KAAKS,QAAQ;QAAC,CAAC;QAChD,GAAIT,KAAKE,GAAG,IAAI;YAAEA,KAAKF,KAAKE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