@foundrykit/seo-plugin 0.0.0-stage → 0.3.1
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 +99 -3
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { articleJsonLd, breadcrumbJsonLd, buildJsonLd, organizationJsonLd, productJsonLd, webPageJsonLd } from './jsonld.js';
|
|
3
|
+
describe('webPageJsonLd', ()=>{
|
|
4
|
+
it('always sets @context and @type', ()=>{
|
|
5
|
+
const result = webPageJsonLd();
|
|
6
|
+
expect(result['@context']).toBe('https://schema.org');
|
|
7
|
+
expect(result['@type']).toBe('WebPage');
|
|
8
|
+
});
|
|
9
|
+
it('includes provided fields', ()=>{
|
|
10
|
+
const result = webPageJsonLd({
|
|
11
|
+
name: 'Home',
|
|
12
|
+
url: 'https://example.com',
|
|
13
|
+
description: 'Desc'
|
|
14
|
+
});
|
|
15
|
+
expect(result.name).toBe('Home');
|
|
16
|
+
expect(result.url).toBe('https://example.com');
|
|
17
|
+
expect(result.description).toBe('Desc');
|
|
18
|
+
});
|
|
19
|
+
it('omits undefined fields', ()=>{
|
|
20
|
+
const result = webPageJsonLd({
|
|
21
|
+
name: 'Home'
|
|
22
|
+
});
|
|
23
|
+
expect(result).not.toHaveProperty('url');
|
|
24
|
+
expect(result).not.toHaveProperty('description');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('articleJsonLd', ()=>{
|
|
28
|
+
it('always sets @context and @type', ()=>{
|
|
29
|
+
const result = articleJsonLd();
|
|
30
|
+
expect(result['@context']).toBe('https://schema.org');
|
|
31
|
+
expect(result['@type']).toBe('Article');
|
|
32
|
+
});
|
|
33
|
+
it('sets author as Person object when passed a string', ()=>{
|
|
34
|
+
const result = articleJsonLd({
|
|
35
|
+
author: 'Jane Smith'
|
|
36
|
+
});
|
|
37
|
+
expect(result.author).toEqual({
|
|
38
|
+
'@type': 'Person',
|
|
39
|
+
name: 'Jane Smith'
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it('sets author as Person object when passed an object', ()=>{
|
|
43
|
+
const result = articleJsonLd({
|
|
44
|
+
author: {
|
|
45
|
+
name: 'Jane Smith',
|
|
46
|
+
url: 'https://example.com'
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
expect(result.author).toEqual({
|
|
50
|
+
'@type': 'Person',
|
|
51
|
+
name: 'Jane Smith',
|
|
52
|
+
url: 'https://example.com'
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it('sets publisher with logo as ImageObject', ()=>{
|
|
56
|
+
const result = articleJsonLd({
|
|
57
|
+
publisher: {
|
|
58
|
+
name: 'Acme',
|
|
59
|
+
logo: 'https://example.com/logo.png'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
expect(result.publisher).toEqual({
|
|
63
|
+
'@type': 'Organization',
|
|
64
|
+
name: 'Acme',
|
|
65
|
+
logo: {
|
|
66
|
+
'@type': 'ImageObject',
|
|
67
|
+
url: 'https://example.com/logo.png'
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it('sets publisher without logo when not provided', ()=>{
|
|
72
|
+
const result = articleJsonLd({
|
|
73
|
+
publisher: {
|
|
74
|
+
name: 'Acme'
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
expect(result.publisher).toEqual({
|
|
78
|
+
'@type': 'Organization',
|
|
79
|
+
name: 'Acme'
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('productJsonLd', ()=>{
|
|
84
|
+
it('always sets @context and @type', ()=>{
|
|
85
|
+
const result = productJsonLd();
|
|
86
|
+
expect(result['@context']).toBe('https://schema.org');
|
|
87
|
+
expect(result['@type']).toBe('Product');
|
|
88
|
+
});
|
|
89
|
+
it('sets brand as Brand object', ()=>{
|
|
90
|
+
const result = productJsonLd({
|
|
91
|
+
brand: 'Acme'
|
|
92
|
+
});
|
|
93
|
+
expect(result.brand).toEqual({
|
|
94
|
+
'@type': 'Brand',
|
|
95
|
+
name: 'Acme'
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
it('sets offers as Offer object with all fields', ()=>{
|
|
99
|
+
const result = productJsonLd({
|
|
100
|
+
offers: {
|
|
101
|
+
price: 9.99,
|
|
102
|
+
currency: 'USD',
|
|
103
|
+
availability: 'InStock',
|
|
104
|
+
url: 'https://example.com'
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
expect(result.offers).toEqual({
|
|
108
|
+
'@type': 'Offer',
|
|
109
|
+
price: 9.99,
|
|
110
|
+
priceCurrency: 'USD',
|
|
111
|
+
availability: 'InStock',
|
|
112
|
+
url: 'https://example.com'
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('includes price of 0', ()=>{
|
|
116
|
+
const result = productJsonLd({
|
|
117
|
+
offers: {
|
|
118
|
+
price: 0
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
expect(result.offers.price).toBe(0);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('organizationJsonLd', ()=>{
|
|
125
|
+
it('always sets @context and @type', ()=>{
|
|
126
|
+
const result = organizationJsonLd();
|
|
127
|
+
expect(result['@context']).toBe('https://schema.org');
|
|
128
|
+
expect(result['@type']).toBe('Organization');
|
|
129
|
+
});
|
|
130
|
+
it('sets logo as ImageObject', ()=>{
|
|
131
|
+
const result = organizationJsonLd({
|
|
132
|
+
logo: 'https://example.com/logo.png'
|
|
133
|
+
});
|
|
134
|
+
expect(result.logo).toEqual({
|
|
135
|
+
'@type': 'ImageObject',
|
|
136
|
+
url: 'https://example.com/logo.png'
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it('sets sameAs array', ()=>{
|
|
140
|
+
const result = organizationJsonLd({
|
|
141
|
+
sameAs: [
|
|
142
|
+
'https://twitter.com/acme',
|
|
143
|
+
'https://linkedin.com/acme'
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
expect(result.sameAs).toEqual([
|
|
147
|
+
'https://twitter.com/acme',
|
|
148
|
+
'https://linkedin.com/acme'
|
|
149
|
+
]);
|
|
150
|
+
});
|
|
151
|
+
it('omits sameAs when empty array', ()=>{
|
|
152
|
+
const result = organizationJsonLd({
|
|
153
|
+
sameAs: []
|
|
154
|
+
});
|
|
155
|
+
expect(result).not.toHaveProperty('sameAs');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('breadcrumbJsonLd', ()=>{
|
|
159
|
+
it('always sets @context and @type', ()=>{
|
|
160
|
+
const result = breadcrumbJsonLd([]);
|
|
161
|
+
expect(result['@context']).toBe('https://schema.org');
|
|
162
|
+
expect(result['@type']).toBe('BreadcrumbList');
|
|
163
|
+
});
|
|
164
|
+
it('maps items to ListItem with 1-based position', ()=>{
|
|
165
|
+
const result = breadcrumbJsonLd([
|
|
166
|
+
{
|
|
167
|
+
id: 'https://example.com',
|
|
168
|
+
name: 'Home'
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
id: 'https://example.com/blog',
|
|
172
|
+
name: 'Blog'
|
|
173
|
+
}
|
|
174
|
+
]);
|
|
175
|
+
expect(result.itemListElement).toEqual([
|
|
176
|
+
{
|
|
177
|
+
'@type': 'ListItem',
|
|
178
|
+
position: 1,
|
|
179
|
+
name: 'Home',
|
|
180
|
+
item: 'https://example.com'
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
'@type': 'ListItem',
|
|
184
|
+
position: 2,
|
|
185
|
+
name: 'Blog',
|
|
186
|
+
item: 'https://example.com/blog'
|
|
187
|
+
}
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe('buildJsonLd', ()=>{
|
|
192
|
+
it('merges overrides onto base', ()=>{
|
|
193
|
+
const base = articleJsonLd({
|
|
194
|
+
headline: 'Base headline',
|
|
195
|
+
url: 'https://example.com'
|
|
196
|
+
});
|
|
197
|
+
const result = buildJsonLd(base, {
|
|
198
|
+
headline: 'Override headline'
|
|
199
|
+
});
|
|
200
|
+
expect(result.headline).toBe('Override headline');
|
|
201
|
+
expect(result.url).toBe('https://example.com');
|
|
202
|
+
});
|
|
203
|
+
it('always preserves @context and @type from base', ()=>{
|
|
204
|
+
const base = articleJsonLd();
|
|
205
|
+
const result = buildJsonLd(base, {
|
|
206
|
+
'@context': 'https://evil.com',
|
|
207
|
+
'@type': 'Hacked'
|
|
208
|
+
});
|
|
209
|
+
expect(result['@context']).toBe('https://schema.org');
|
|
210
|
+
expect(result['@type']).toBe('Article');
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
//# sourceMappingURL=jsonld.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/jsonld.test.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest';\n\nimport {\n articleJsonLd,\n breadcrumbJsonLd,\n buildJsonLd,\n organizationJsonLd,\n productJsonLd,\n webPageJsonLd,\n} from './jsonld.js';\n\ndescribe('webPageJsonLd', () => {\n it('always sets @context and @type', () => {\n const result = webPageJsonLd();\n expect(result['@context']).toBe('https://schema.org');\n expect(result['@type']).toBe('WebPage');\n });\n\n it('includes provided fields', () => {\n const result = webPageJsonLd({\n name: 'Home',\n url: 'https://example.com',\n description: 'Desc',\n });\n expect(result.name).toBe('Home');\n expect(result.url).toBe('https://example.com');\n expect(result.description).toBe('Desc');\n });\n\n it('omits undefined fields', () => {\n const result = webPageJsonLd({ name: 'Home' });\n expect(result).not.toHaveProperty('url');\n expect(result).not.toHaveProperty('description');\n });\n});\n\ndescribe('articleJsonLd', () => {\n it('always sets @context and @type', () => {\n const result = articleJsonLd();\n expect(result['@context']).toBe('https://schema.org');\n expect(result['@type']).toBe('Article');\n });\n\n it('sets author as Person object when passed a string', () => {\n const result = articleJsonLd({ author: 'Jane Smith' });\n expect(result.author).toEqual({ '@type': 'Person', name: 'Jane Smith' });\n });\n\n it('sets author as Person object when passed an object', () => {\n const result = articleJsonLd({\n author: { name: 'Jane Smith', url: 'https://example.com' },\n });\n expect(result.author).toEqual({\n '@type': 'Person',\n name: 'Jane Smith',\n url: 'https://example.com',\n });\n });\n\n it('sets publisher with logo as ImageObject', () => {\n const result = articleJsonLd({\n publisher: { name: 'Acme', logo: 'https://example.com/logo.png' },\n });\n expect(result.publisher).toEqual({\n '@type': 'Organization',\n name: 'Acme',\n logo: { '@type': 'ImageObject', url: 'https://example.com/logo.png' },\n });\n });\n\n it('sets publisher without logo when not provided', () => {\n const result = articleJsonLd({ publisher: { name: 'Acme' } });\n expect(result.publisher).toEqual({ '@type': 'Organization', name: 'Acme' });\n });\n});\n\ndescribe('productJsonLd', () => {\n it('always sets @context and @type', () => {\n const result = productJsonLd();\n expect(result['@context']).toBe('https://schema.org');\n expect(result['@type']).toBe('Product');\n });\n\n it('sets brand as Brand object', () => {\n const result = productJsonLd({ brand: 'Acme' });\n expect(result.brand).toEqual({ '@type': 'Brand', name: 'Acme' });\n });\n\n it('sets offers as Offer object with all fields', () => {\n const result = productJsonLd({\n offers: {\n price: 9.99,\n currency: 'USD',\n availability: 'InStock',\n url: 'https://example.com',\n },\n });\n expect(result.offers).toEqual({\n '@type': 'Offer',\n price: 9.99,\n priceCurrency: 'USD',\n availability: 'InStock',\n url: 'https://example.com',\n });\n });\n\n it('includes price of 0', () => {\n const result = productJsonLd({ offers: { price: 0 } });\n expect((result.offers as Record<string, unknown>).price).toBe(0);\n });\n});\n\ndescribe('organizationJsonLd', () => {\n it('always sets @context and @type', () => {\n const result = organizationJsonLd();\n expect(result['@context']).toBe('https://schema.org');\n expect(result['@type']).toBe('Organization');\n });\n\n it('sets logo as ImageObject', () => {\n const result = organizationJsonLd({ logo: 'https://example.com/logo.png' });\n expect(result.logo).toEqual({\n '@type': 'ImageObject',\n url: 'https://example.com/logo.png',\n });\n });\n\n it('sets sameAs array', () => {\n const result = organizationJsonLd({\n sameAs: ['https://twitter.com/acme', 'https://linkedin.com/acme'],\n });\n expect(result.sameAs).toEqual([\n 'https://twitter.com/acme',\n 'https://linkedin.com/acme',\n ]);\n });\n\n it('omits sameAs when empty array', () => {\n const result = organizationJsonLd({ sameAs: [] });\n expect(result).not.toHaveProperty('sameAs');\n });\n});\n\ndescribe('breadcrumbJsonLd', () => {\n it('always sets @context and @type', () => {\n const result = breadcrumbJsonLd([]);\n expect(result['@context']).toBe('https://schema.org');\n expect(result['@type']).toBe('BreadcrumbList');\n });\n\n it('maps items to ListItem with 1-based position', () => {\n const result = breadcrumbJsonLd([\n { id: 'https://example.com', name: 'Home' },\n { id: 'https://example.com/blog', name: 'Blog' },\n ]);\n expect(result.itemListElement).toEqual([\n {\n '@type': 'ListItem',\n position: 1,\n name: 'Home',\n item: 'https://example.com',\n },\n {\n '@type': 'ListItem',\n position: 2,\n name: 'Blog',\n item: 'https://example.com/blog',\n },\n ]);\n });\n});\n\ndescribe('buildJsonLd', () => {\n it('merges overrides onto base', () => {\n const base = articleJsonLd({\n headline: 'Base headline',\n url: 'https://example.com',\n });\n const result = buildJsonLd(base, { headline: 'Override headline' });\n expect(result.headline).toBe('Override headline');\n expect(result.url).toBe('https://example.com');\n });\n\n it('always preserves @context and @type from base', () => {\n const base = articleJsonLd();\n const result = buildJsonLd(base, {\n '@context': 'https://evil.com' as 'https://schema.org',\n '@type': 'Hacked',\n });\n expect(result['@context']).toBe('https://schema.org');\n expect(result['@type']).toBe('Article');\n });\n});\n"],"names":["describe","expect","it","articleJsonLd","breadcrumbJsonLd","buildJsonLd","organizationJsonLd","productJsonLd","webPageJsonLd","result","toBe","name","url","description","not","toHaveProperty","author","toEqual","publisher","logo","brand","offers","price","currency","availability","priceCurrency","sameAs","id","itemListElement","position","item","base","headline"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAE9C,SACEC,aAAa,EACbC,gBAAgB,EAChBC,WAAW,EACXC,kBAAkB,EAClBC,aAAa,EACbC,aAAa,QACR,cAAc;AAErBR,SAAS,iBAAiB;IACxBE,GAAG,kCAAkC;QACnC,MAAMO,SAASD;QACfP,OAAOQ,MAAM,CAAC,WAAW,EAAEC,IAAI,CAAC;QAChCT,OAAOQ,MAAM,CAAC,QAAQ,EAAEC,IAAI,CAAC;IAC/B;IAEAR,GAAG,4BAA4B;QAC7B,MAAMO,SAASD,cAAc;YAC3BG,MAAM;YACNC,KAAK;YACLC,aAAa;QACf;QACAZ,OAAOQ,OAAOE,IAAI,EAAED,IAAI,CAAC;QACzBT,OAAOQ,OAAOG,GAAG,EAAEF,IAAI,CAAC;QACxBT,OAAOQ,OAAOI,WAAW,EAAEH,IAAI,CAAC;IAClC;IAEAR,GAAG,0BAA0B;QAC3B,MAAMO,SAASD,cAAc;YAAEG,MAAM;QAAO;QAC5CV,OAAOQ,QAAQK,GAAG,CAACC,cAAc,C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QAClCH,OAAOQ,MAAM,CAAC,WAAW,EAAEC,IAAI,CAAC;QAChCT,OAAOQ,MAAM,CAAC,QAAQ,EAAEC,IAAI,CAAC;IAC/B;IAEAR,GAAG,gDAAgD;QACjD,MAAMO,SAASL,iBAAiB;YAC9B;gBAAEuB,IAAI;gBAAuBhB,MAAM;YAAO;YAC1C;gBAAEgB,IAAI;gBAA4BhB,MAAM;YAAO;SAChD;QACDV,OAAOQ,OAAOmB,eAAe,EAAEX,OAAO,CAAC;YACrC;gBACE,SAAS;gBACTY,UAAU;gBACVlB,MAAM;gBACNmB,MAAM;YACR;YACA;gBACE,SAAS;gBACTD,UAAU;gBACVlB,MAAM;gBACNmB,MAAM;YACR;SACD;IACH;AACF;AAEA9B,SAAS,eAAe;IACtBE,GAAG,8BAA8B;QAC/B,MAAM6B,OAAO5B,cAAc;YACzB6B,UAAU;YACVpB,KAAK;QACP;QACA,MAAMH,SAASJ,YAAY0B,MAAM;YAAEC,UAAU;QAAoB;QACjE/B,OAAOQ,OAAOuB,QAAQ,EAAEtB,IAAI,CAAC;QAC7BT,OAAOQ,OAAOG,GAAG,EAAEF,IAAI,CAAC;IAC1B;IAEAR,GAAG,iDAAiD;QAClD,MAAM6B,OAAO5B;QACb,MAAMM,SAASJ,YAAY0B,MAAM;YAC/B,YAAY;YACZ,SAAS;QACX;QACA9B,OAAOQ,MAAM,CAAC,WAAW,EAAEC,IAAI,CAAC;QAChCT,OAAOQ,MAAM,CAAC,QAAQ,EAAEC,IAAI,CAAC;IAC/B;AACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DocWithMeta, GlobalSeoDefaults } from './helpers.js';
|
|
2
|
+
export type MetadataResult = {
|
|
3
|
+
alternates?: {
|
|
4
|
+
canonical?: string;
|
|
5
|
+
languages?: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
description?: string;
|
|
8
|
+
openGraph?: {
|
|
9
|
+
description?: string;
|
|
10
|
+
images?: Array<{
|
|
11
|
+
url: string;
|
|
12
|
+
}>;
|
|
13
|
+
title?: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
};
|
|
16
|
+
robots?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
twitter?: {
|
|
19
|
+
card?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
images?: string[];
|
|
22
|
+
site?: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type ToNextMetadataOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* Base URL for the site. Available for future use (e.g. resolving relative URLs).
|
|
29
|
+
* Does not affect the output of this function currently.
|
|
30
|
+
*/
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* OpenGraph type to set on og:type. Defaults to 'website'.
|
|
34
|
+
*/
|
|
35
|
+
openGraphType?: 'article' | 'product' | 'website';
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Builds a Next.js-compatible Metadata object from a Payload document and
|
|
39
|
+
* optional global SEO defaults. The return type is structurally compatible
|
|
40
|
+
* with Next.js `Metadata` so it can be returned directly from a
|
|
41
|
+
* `generateMetadata()` page function without a type cast.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // app/blog/[slug]/page.tsx
|
|
45
|
+
* import { toNextMetadata } from '@foundrykit/seo-plugin/next'
|
|
46
|
+
*
|
|
47
|
+
* export async function generateMetadata({ params }) {
|
|
48
|
+
* const doc = await payload.findByID({ collection: 'posts', id: params.id })
|
|
49
|
+
* const globals = await payload.findGlobal({ slug: 'global-seo' })
|
|
50
|
+
* return toNextMetadata(doc, globals)
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
export declare const toNextMetadata: (doc: DocWithMeta, globals?: GlobalSeoDefaults, options?: ToNextMetadataOptions) => MetadataResult;
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { resolveMeta } from './helpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a Next.js-compatible Metadata object from a Payload document and
|
|
4
|
+
* optional global SEO defaults. The return type is structurally compatible
|
|
5
|
+
* with Next.js `Metadata` so it can be returned directly from a
|
|
6
|
+
* `generateMetadata()` page function without a type cast.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // app/blog/[slug]/page.tsx
|
|
10
|
+
* import { toNextMetadata } from '@foundrykit/seo-plugin/next'
|
|
11
|
+
*
|
|
12
|
+
* export async function generateMetadata({ params }) {
|
|
13
|
+
* const doc = await payload.findByID({ collection: 'posts', id: params.id })
|
|
14
|
+
* const globals = await payload.findGlobal({ slug: 'global-seo' })
|
|
15
|
+
* return toNextMetadata(doc, globals)
|
|
16
|
+
* }
|
|
17
|
+
*/ export const toNextMetadata = (doc, globals, options = {})=>{
|
|
18
|
+
const resolved = resolveMeta(doc, {
|
|
19
|
+
globals
|
|
20
|
+
});
|
|
21
|
+
// ------------------------------------------------------------------
|
|
22
|
+
// Robots
|
|
23
|
+
// Per-document noindex/nofollow booleans take precedence over the
|
|
24
|
+
// global robots directive. When neither is set, the global directive
|
|
25
|
+
// is used (useful for staging sites). If nothing is configured, the
|
|
26
|
+
// robots key is omitted entirely so the browser default applies.
|
|
27
|
+
// ------------------------------------------------------------------
|
|
28
|
+
let robotsString;
|
|
29
|
+
const robotsParts = [];
|
|
30
|
+
if (resolved.noindex) robotsParts.push('noindex');
|
|
31
|
+
if (resolved.nofollow) robotsParts.push('nofollow');
|
|
32
|
+
if (robotsParts.length > 0) {
|
|
33
|
+
robotsString = robotsParts.join(', ');
|
|
34
|
+
} else if (globals?.robots) {
|
|
35
|
+
robotsString = globals.robots;
|
|
36
|
+
}
|
|
37
|
+
// ------------------------------------------------------------------
|
|
38
|
+
// Alternates
|
|
39
|
+
// ------------------------------------------------------------------
|
|
40
|
+
const alternatesResult = {};
|
|
41
|
+
const canonical = resolved.url || undefined;
|
|
42
|
+
if (canonical) {
|
|
43
|
+
alternatesResult.canonical = canonical;
|
|
44
|
+
}
|
|
45
|
+
if (resolved.alternates.length > 0) {
|
|
46
|
+
alternatesResult.languages = Object.fromEntries(resolved.alternates.map(({ locale, url })=>[
|
|
47
|
+
locale,
|
|
48
|
+
url
|
|
49
|
+
]));
|
|
50
|
+
}
|
|
51
|
+
const hasAlternates = Boolean(canonical || resolved.alternates.length > 0);
|
|
52
|
+
// ------------------------------------------------------------------
|
|
53
|
+
// OpenGraph
|
|
54
|
+
// ------------------------------------------------------------------
|
|
55
|
+
const ogImages = resolved.image ? [
|
|
56
|
+
{
|
|
57
|
+
url: resolved.image
|
|
58
|
+
}
|
|
59
|
+
] : [];
|
|
60
|
+
const openGraph = {
|
|
61
|
+
type: options.openGraphType ?? 'website',
|
|
62
|
+
...resolved.title && {
|
|
63
|
+
title: resolved.title
|
|
64
|
+
},
|
|
65
|
+
...resolved.description && {
|
|
66
|
+
description: resolved.description
|
|
67
|
+
},
|
|
68
|
+
...ogImages.length > 0 && {
|
|
69
|
+
images: ogImages
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// ------------------------------------------------------------------
|
|
73
|
+
// Twitter
|
|
74
|
+
// ------------------------------------------------------------------
|
|
75
|
+
const twitterImages = resolved.image ? [
|
|
76
|
+
resolved.image
|
|
77
|
+
] : [];
|
|
78
|
+
const twitter = {
|
|
79
|
+
card: 'summary_large_image',
|
|
80
|
+
...globals?.twitterHandle && {
|
|
81
|
+
site: globals.twitterHandle
|
|
82
|
+
},
|
|
83
|
+
...resolved.title && {
|
|
84
|
+
title: resolved.title
|
|
85
|
+
},
|
|
86
|
+
...resolved.description && {
|
|
87
|
+
description: resolved.description
|
|
88
|
+
},
|
|
89
|
+
...twitterImages.length > 0 && {
|
|
90
|
+
images: twitterImages
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
// ------------------------------------------------------------------
|
|
94
|
+
// Assemble result
|
|
95
|
+
// ------------------------------------------------------------------
|
|
96
|
+
return {
|
|
97
|
+
...resolved.title && {
|
|
98
|
+
title: resolved.title
|
|
99
|
+
},
|
|
100
|
+
...resolved.description && {
|
|
101
|
+
description: resolved.description
|
|
102
|
+
},
|
|
103
|
+
...robotsString !== undefined && {
|
|
104
|
+
robots: robotsString
|
|
105
|
+
},
|
|
106
|
+
...hasAlternates && {
|
|
107
|
+
alternates: alternatesResult
|
|
108
|
+
},
|
|
109
|
+
openGraph,
|
|
110
|
+
twitter
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/metadata.ts"],"sourcesContent":["import type { DocWithMeta, GlobalSeoDefaults } from './helpers.js';\n\nimport { resolveMeta } from './helpers.js';\n\nexport type MetadataResult = {\n alternates?: {\n canonical?: string;\n languages?: Record<string, string>;\n };\n description?: string;\n openGraph?: {\n description?: string;\n images?: Array<{ url: string }>;\n title?: string;\n type?: string;\n };\n robots?: string;\n title?: string;\n twitter?: {\n card?: string;\n description?: string;\n images?: string[];\n site?: string;\n title?: string;\n };\n};\n\nexport type ToNextMetadataOptions = {\n /**\n * Base URL for the site. Available for future use (e.g. resolving relative URLs).\n * Does not affect the output of this function currently.\n */\n baseUrl?: string;\n /**\n * OpenGraph type to set on og:type. Defaults to 'website'.\n */\n openGraphType?: 'article' | 'product' | 'website';\n};\n\n/**\n * Builds a Next.js-compatible Metadata object from a Payload document and\n * optional global SEO defaults. The return type is structurally compatible\n * with Next.js `Metadata` so it can be returned directly from a\n * `generateMetadata()` page function without a type cast.\n *\n * @example\n * // app/blog/[slug]/page.tsx\n * import { toNextMetadata } from '@foundrykit/seo-plugin/next'\n *\n * export async function generateMetadata({ params }) {\n * const doc = await payload.findByID({ collection: 'posts', id: params.id })\n * const globals = await payload.findGlobal({ slug: 'global-seo' })\n * return toNextMetadata(doc, globals)\n * }\n */\nexport const toNextMetadata = (\n doc: DocWithMeta,\n globals?: GlobalSeoDefaults,\n options: ToNextMetadataOptions = {}\n): MetadataResult => {\n const resolved = resolveMeta(doc, { globals });\n\n // ------------------------------------------------------------------\n // Robots\n // Per-document noindex/nofollow booleans take precedence over the\n // global robots directive. When neither is set, the global directive\n // is used (useful for staging sites). If nothing is configured, the\n // robots key is omitted entirely so the browser default applies.\n // ------------------------------------------------------------------\n let robotsString: string | undefined;\n const robotsParts: string[] = [];\n if (resolved.noindex) robotsParts.push('noindex');\n if (resolved.nofollow) robotsParts.push('nofollow');\n\n if (robotsParts.length > 0) {\n robotsString = robotsParts.join(', ');\n } else if (globals?.robots) {\n robotsString = globals.robots;\n }\n\n // ------------------------------------------------------------------\n // Alternates\n // ------------------------------------------------------------------\n const alternatesResult: MetadataResult['alternates'] = {};\n const canonical = resolved.url || undefined;\n if (canonical) {\n alternatesResult.canonical = canonical;\n }\n if (resolved.alternates.length > 0) {\n alternatesResult.languages = Object.fromEntries(\n resolved.alternates.map(({ locale, url }) => [locale, url])\n );\n }\n const hasAlternates = Boolean(canonical || resolved.alternates.length > 0);\n\n // ------------------------------------------------------------------\n // OpenGraph\n // ------------------------------------------------------------------\n const ogImages = resolved.image ? [{ url: resolved.image }] : [];\n const openGraph: MetadataResult['openGraph'] = {\n type: options.openGraphType ?? 'website',\n ...(resolved.title && { title: resolved.title }),\n ...(resolved.description && { description: resolved.description }),\n ...(ogImages.length > 0 && { images: ogImages }),\n };\n\n // ------------------------------------------------------------------\n // Twitter\n // ------------------------------------------------------------------\n const twitterImages = resolved.image ? [resolved.image] : [];\n const twitter: MetadataResult['twitter'] = {\n card: 'summary_large_image',\n ...(globals?.twitterHandle && { site: globals.twitterHandle }),\n ...(resolved.title && { title: resolved.title }),\n ...(resolved.description && { description: resolved.description }),\n ...(twitterImages.length > 0 && { images: twitterImages }),\n };\n\n // ------------------------------------------------------------------\n // Assemble result\n // ------------------------------------------------------------------\n return {\n ...(resolved.title && { title: resolved.title }),\n ...(resolved.description && { description: resolved.description }),\n ...(robotsString !== undefined && { robots: robotsString }),\n ...(hasAlternates && { alternates: alternatesResult }),\n openGraph,\n twitter,\n };\n};\n"],"names":["resolveMeta","toNextMetadata","doc","globals","options","resolved","robotsString","robotsParts","noindex","push","nofollow","length","join","robots","alternatesResult","canonical","url","undefined","alternates","languages","Object","fromEntries","map","locale","hasAlternates","Boolean","ogImages","image","openGraph","type","openGraphType","title","description","images","twitterImages","twitter","card","twitterHandle","site"],"mappings":"AAEA,SAASA,WAAW,QAAQ,eAAe;AAqC3C;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,iBAAiB,CAC5BC,KACAC,SACAC,UAAiC,CAAC,CAAC;IAEnC,MAAMC,WAAWL,YAAYE,KAAK;QAAEC;IAAQ;IAE5C,qEAAqE;IACrE,SAAS;IACT,kEAAkE;IAClE,qEAAqE;IACrE,oEAAoE;IACpE,iEAAiE;IACjE,qEAAqE;IACrE,IAAIG;IACJ,MAAMC,cAAwB,EAAE;IAChC,IAAIF,SAASG,OAAO,EAAED,YAAYE,IAAI,CAAC;IACvC,IAAIJ,SAASK,QAAQ,EAAEH,YAAYE,IAAI,CAAC;IAExC,IAAIF,YAAYI,MAAM,GAAG,GAAG;QAC1BL,eAAeC,YAAYK,IAAI,CAAC;IAClC,OAAO,IAAIT,SAASU,QAAQ;QAC1BP,eAAeH,QAAQU,MAAM;IAC/B;IAEA,qEAAqE;IACrE,aAAa;IACb,qEAAqE;IACrE,MAAMC,mBAAiD,CAAC;IACxD,MAAMC,YAAYV,SAASW,GAAG,IAAIC;IAClC,IAAIF,WAAW;QACbD,iBAAiBC,SAAS,GAAGA;IAC/B;IACA,IAAIV,SAASa,UAAU,CAACP,MAAM,GAAG,GAAG;QAClCG,iBAAiBK,SAAS,GAAGC,OAAOC,WAAW,CAC7ChB,SAASa,UAAU,CAACI,GAAG,CAAC,CAAC,EAAEC,MAAM,EAAEP,GAAG,EAAE,GAAK;gBAACO;gBAAQP;aAAI;IAE9D;IACA,MAAMQ,gBAAgBC,QAAQV,aAAaV,SAASa,UAAU,CAACP,MAAM,GAAG;I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