@ingram-tech/nk-seo 0.8.0 → 0.9.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 +6 -15
- package/dist/alternates.d.ts +18 -25
- package/dist/alternates.d.ts.map +1 -1
- package/dist/alternates.js +15 -39
- package/dist/alternates.js.map +1 -1
- package/package.json +7 -4
- package/src/alternates.ts +127 -0
- package/src/components.ts +4 -0
- package/src/hreflang.tsx +70 -0
- package/src/index.ts +92 -0
- package/src/json-ld.tsx +35 -0
- package/src/metadata.ts +203 -0
- package/src/og.tsx +155 -0
- package/src/routes.ts +170 -0
- package/src/schema.ts +980 -0
- package/src/url.ts +23 -0
- package/src/verify.ts +195 -0
package/src/schema.ts
ADDED
|
@@ -0,0 +1,980 @@
|
|
|
1
|
+
import { absoluteUrl } from "./url.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed schema.org JSON-LD builders. Each returns a typed node ready to hand
|
|
5
|
+
* to `<JsonLd>` (from "@ingram-tech/nk-seo/components").
|
|
6
|
+
*
|
|
7
|
+
* The standalone builders take values as-is: pass **absolute** URLs for
|
|
8
|
+
* `url`/`image`/`logo` fields. If your pages work in site-relative paths and
|
|
9
|
+
* share one Organization, prefer {@link createSeo}, which resolves paths against
|
|
10
|
+
* a base URL (including nested `logo`/`offers.url` fields) and injects the
|
|
11
|
+
* publisher/provider for you.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const CONTEXT = "https://schema.org";
|
|
15
|
+
|
|
16
|
+
/** A loosely-typed schema.org node. The builders return more precise subtypes. */
|
|
17
|
+
export type JsonLdNode = Record<string, unknown>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Escape hatch carried by every builder input: properties shallow-merged over
|
|
21
|
+
* the built payload (they win on conflict). schema.org is far larger than any
|
|
22
|
+
* builder surface, and without this one extra property — an `inLanguage`, an
|
|
23
|
+
* `about`, a `potentialAction` — forces the whole node back to a hand-written
|
|
24
|
+
* literal. Fields passed here are not reflected in the returned node type.
|
|
25
|
+
*/
|
|
26
|
+
export interface WithExtra {
|
|
27
|
+
extra?: JsonLdNode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A top-level schema.org node: the payload plus its `@context`. */
|
|
31
|
+
export type WithContext<T> = T & { "@context": "https://schema.org" };
|
|
32
|
+
|
|
33
|
+
// --- FAQPage ---------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
export interface FaqItem {
|
|
36
|
+
question: string;
|
|
37
|
+
answer: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type QuestionNode = {
|
|
41
|
+
"@type": "Question";
|
|
42
|
+
name: string;
|
|
43
|
+
acceptedAnswer: { "@type": "Answer"; text: string };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type FaqPageNode = {
|
|
47
|
+
"@type": "FAQPage";
|
|
48
|
+
mainEntity: QuestionNode[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** FAQPage: marks up a list of question/answer pairs for FAQ rich results. */
|
|
52
|
+
export function faqPage(
|
|
53
|
+
items: FaqItem[],
|
|
54
|
+
extra?: JsonLdNode,
|
|
55
|
+
): WithContext<FaqPageNode> {
|
|
56
|
+
return {
|
|
57
|
+
"@context": CONTEXT,
|
|
58
|
+
"@type": "FAQPage",
|
|
59
|
+
mainEntity: items.map((item) => ({
|
|
60
|
+
"@type": "Question",
|
|
61
|
+
name: item.question,
|
|
62
|
+
acceptedAnswer: { "@type": "Answer", text: item.answer },
|
|
63
|
+
})),
|
|
64
|
+
...extra,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// --- BreadcrumbList --------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
export interface BreadcrumbItem {
|
|
71
|
+
name: string;
|
|
72
|
+
/** Absolute URL of the crumb. */
|
|
73
|
+
url: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type ListItemNode = {
|
|
77
|
+
"@type": "ListItem";
|
|
78
|
+
position: number;
|
|
79
|
+
name: string;
|
|
80
|
+
item: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type BreadcrumbListNode = {
|
|
84
|
+
"@type": "BreadcrumbList";
|
|
85
|
+
itemListElement: ListItemNode[];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** BreadcrumbList: the trail of links Google shows in place of the raw URL. */
|
|
89
|
+
export function breadcrumbList(
|
|
90
|
+
items: BreadcrumbItem[],
|
|
91
|
+
extra?: JsonLdNode,
|
|
92
|
+
): WithContext<BreadcrumbListNode> {
|
|
93
|
+
return {
|
|
94
|
+
"@context": CONTEXT,
|
|
95
|
+
"@type": "BreadcrumbList",
|
|
96
|
+
itemListElement: items.map((item, index) => ({
|
|
97
|
+
"@type": "ListItem",
|
|
98
|
+
position: index + 1,
|
|
99
|
+
name: item.name,
|
|
100
|
+
item: item.url,
|
|
101
|
+
})),
|
|
102
|
+
...extra,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// --- Organization ----------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
export interface OrganizationInput extends WithExtra {
|
|
109
|
+
name: string;
|
|
110
|
+
/** Absolute URL of the organization's site. */
|
|
111
|
+
url?: string;
|
|
112
|
+
/** Absolute URL of the logo image. */
|
|
113
|
+
logo?: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
email?: string;
|
|
116
|
+
telephone?: string;
|
|
117
|
+
/** Registered/office postal address. */
|
|
118
|
+
address?: PostalAddressInput;
|
|
119
|
+
/** Profile/social URLs that corroborate the entity (LinkedIn, Crunchbase…). */
|
|
120
|
+
sameAs?: string[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type PostalAddressNode = { "@type": "PostalAddress" } & PostalAddressInput;
|
|
124
|
+
|
|
125
|
+
export type ImageObjectNode = { "@type": "ImageObject"; url: string };
|
|
126
|
+
|
|
127
|
+
export type OrganizationNode = {
|
|
128
|
+
"@type": "Organization";
|
|
129
|
+
name: string;
|
|
130
|
+
url?: string;
|
|
131
|
+
logo?: ImageObjectNode;
|
|
132
|
+
description?: string;
|
|
133
|
+
email?: string;
|
|
134
|
+
telephone?: string;
|
|
135
|
+
address?: PostalAddressNode;
|
|
136
|
+
sameAs?: string[];
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** Organization node without `@context`, for embedding as publisher/provider. */
|
|
140
|
+
function organizationNode(input: OrganizationInput): OrganizationNode {
|
|
141
|
+
return {
|
|
142
|
+
"@type": "Organization",
|
|
143
|
+
name: input.name,
|
|
144
|
+
...(input.url ? { url: input.url } : {}),
|
|
145
|
+
...(input.logo ? { logo: { "@type": "ImageObject", url: input.logo } } : {}),
|
|
146
|
+
...(input.description ? { description: input.description } : {}),
|
|
147
|
+
...(input.email ? { email: input.email } : {}),
|
|
148
|
+
...(input.telephone ? { telephone: input.telephone } : {}),
|
|
149
|
+
...(input.address
|
|
150
|
+
? { address: { "@type": "PostalAddress", ...input.address } }
|
|
151
|
+
: {}),
|
|
152
|
+
...(input.sameAs?.length ? { sameAs: input.sameAs } : {}),
|
|
153
|
+
...input.extra,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Organization: the entity behind the site (for the knowledge panel). */
|
|
158
|
+
export function organization(input: OrganizationInput): WithContext<OrganizationNode> {
|
|
159
|
+
return { "@context": CONTEXT, ...organizationNode(input) };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// --- WebSite ---------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
export interface WebsiteInput extends WithExtra {
|
|
165
|
+
name: string;
|
|
166
|
+
/** Absolute URL of the site root. */
|
|
167
|
+
url: string;
|
|
168
|
+
publisher?: OrganizationInput;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type WebsiteNode = {
|
|
172
|
+
"@type": "WebSite";
|
|
173
|
+
name: string;
|
|
174
|
+
url: string;
|
|
175
|
+
publisher?: OrganizationNode;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** WebSite: identifies the site as an entity; pair with {@link organization}. */
|
|
179
|
+
export function website(input: WebsiteInput): WithContext<WebsiteNode> {
|
|
180
|
+
return {
|
|
181
|
+
"@context": CONTEXT,
|
|
182
|
+
"@type": "WebSite",
|
|
183
|
+
name: input.name,
|
|
184
|
+
url: input.url,
|
|
185
|
+
...(input.publisher ? { publisher: organizationNode(input.publisher) } : {}),
|
|
186
|
+
...input.extra,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// --- SoftwareApplication ---------------------------------------------------
|
|
191
|
+
|
|
192
|
+
export interface OfferInput {
|
|
193
|
+
priceCurrency: string;
|
|
194
|
+
/** Single price. Mutually exclusive with low/high (which emit an AggregateOffer). */
|
|
195
|
+
price?: string | number;
|
|
196
|
+
lowPrice?: string | number;
|
|
197
|
+
highPrice?: string | number;
|
|
198
|
+
offerCount?: string | number;
|
|
199
|
+
/** Absolute URL of the pricing/offer page. */
|
|
200
|
+
url?: string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type OfferNode = {
|
|
204
|
+
"@type": "Offer";
|
|
205
|
+
priceCurrency: string;
|
|
206
|
+
price?: string;
|
|
207
|
+
url?: string;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type AggregateOfferNode = {
|
|
211
|
+
"@type": "AggregateOffer";
|
|
212
|
+
priceCurrency: string;
|
|
213
|
+
lowPrice?: string;
|
|
214
|
+
highPrice?: string;
|
|
215
|
+
offerCount?: string;
|
|
216
|
+
url?: string;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
function offerNode(offer: OfferInput): OfferNode | AggregateOfferNode {
|
|
220
|
+
const isAggregate = offer.lowPrice !== undefined || offer.highPrice !== undefined;
|
|
221
|
+
if (isAggregate) {
|
|
222
|
+
return {
|
|
223
|
+
"@type": "AggregateOffer",
|
|
224
|
+
priceCurrency: offer.priceCurrency,
|
|
225
|
+
...(offer.lowPrice !== undefined
|
|
226
|
+
? { lowPrice: String(offer.lowPrice) }
|
|
227
|
+
: {}),
|
|
228
|
+
...(offer.highPrice !== undefined
|
|
229
|
+
? { highPrice: String(offer.highPrice) }
|
|
230
|
+
: {}),
|
|
231
|
+
...(offer.offerCount !== undefined
|
|
232
|
+
? { offerCount: String(offer.offerCount) }
|
|
233
|
+
: {}),
|
|
234
|
+
...(offer.url ? { url: offer.url } : {}),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
"@type": "Offer",
|
|
239
|
+
priceCurrency: offer.priceCurrency,
|
|
240
|
+
...(offer.price !== undefined ? { price: String(offer.price) } : {}),
|
|
241
|
+
...(offer.url ? { url: offer.url } : {}),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface SoftwareApplicationInput extends WithExtra {
|
|
246
|
+
name: string;
|
|
247
|
+
description?: string;
|
|
248
|
+
/** Absolute URL of the app/marketing page. */
|
|
249
|
+
url?: string;
|
|
250
|
+
/** e.g. "BusinessApplication", "FinanceApplication". */
|
|
251
|
+
applicationCategory?: string;
|
|
252
|
+
/** e.g. "Web". */
|
|
253
|
+
operatingSystem?: string;
|
|
254
|
+
offers?: OfferInput;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type SoftwareApplicationNode = {
|
|
258
|
+
"@type": "SoftwareApplication";
|
|
259
|
+
name: string;
|
|
260
|
+
applicationCategory?: string;
|
|
261
|
+
operatingSystem?: string;
|
|
262
|
+
url?: string;
|
|
263
|
+
description?: string;
|
|
264
|
+
offers?: OfferNode | AggregateOfferNode;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/** SoftwareApplication: marks a product page as an app for rich results. */
|
|
268
|
+
export function softwareApplication(
|
|
269
|
+
input: SoftwareApplicationInput,
|
|
270
|
+
): WithContext<SoftwareApplicationNode> {
|
|
271
|
+
return {
|
|
272
|
+
"@context": CONTEXT,
|
|
273
|
+
"@type": "SoftwareApplication",
|
|
274
|
+
name: input.name,
|
|
275
|
+
...(input.applicationCategory
|
|
276
|
+
? { applicationCategory: input.applicationCategory }
|
|
277
|
+
: {}),
|
|
278
|
+
...(input.operatingSystem ? { operatingSystem: input.operatingSystem } : {}),
|
|
279
|
+
...(input.url ? { url: input.url } : {}),
|
|
280
|
+
...(input.description ? { description: input.description } : {}),
|
|
281
|
+
...(input.offers ? { offers: offerNode(input.offers) } : {}),
|
|
282
|
+
...input.extra,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// --- Article ---------------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* schema.org Article subtypes worth marking up. `TechArticle` is the right node
|
|
290
|
+
* for API/developer docs (`proficiencyLevel`/`dependencies` via `extra`).
|
|
291
|
+
*/
|
|
292
|
+
export type ArticleType =
|
|
293
|
+
| "Article"
|
|
294
|
+
| "BlogPosting"
|
|
295
|
+
| "NewsArticle"
|
|
296
|
+
| "ScholarlyArticle"
|
|
297
|
+
| "TechArticle"
|
|
298
|
+
| "Report";
|
|
299
|
+
|
|
300
|
+
export interface ArticleAuthor {
|
|
301
|
+
name: string;
|
|
302
|
+
/** Absolute URL of the author's profile/page. */
|
|
303
|
+
url?: string;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface ArticleInput extends WithExtra {
|
|
307
|
+
headline: string;
|
|
308
|
+
/** Absolute canonical URL of the article. */
|
|
309
|
+
url: string;
|
|
310
|
+
description?: string;
|
|
311
|
+
type?: ArticleType;
|
|
312
|
+
datePublished?: string;
|
|
313
|
+
/** Defaults to `datePublished` when omitted. */
|
|
314
|
+
dateModified?: string;
|
|
315
|
+
authors?: ArticleAuthor[];
|
|
316
|
+
/** Absolute URL of the lead image. */
|
|
317
|
+
image?: string;
|
|
318
|
+
keywords?: string[];
|
|
319
|
+
publisher?: OrganizationInput;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export type ArticleAuthorNode = { "@type": "Person"; name: string; url?: string };
|
|
323
|
+
|
|
324
|
+
export type ArticleNode = {
|
|
325
|
+
"@type": ArticleType;
|
|
326
|
+
headline: string;
|
|
327
|
+
url: string;
|
|
328
|
+
mainEntityOfPage: string;
|
|
329
|
+
description?: string;
|
|
330
|
+
author?: ArticleAuthorNode[];
|
|
331
|
+
publisher?: OrganizationNode;
|
|
332
|
+
datePublished?: string;
|
|
333
|
+
dateModified?: string;
|
|
334
|
+
image?: string;
|
|
335
|
+
keywords?: string[];
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/** Article (or one of its {@link ArticleType} subtypes) for editorial pages. */
|
|
339
|
+
export function article(input: ArticleInput): WithContext<ArticleNode> {
|
|
340
|
+
const dateModified = input.dateModified ?? input.datePublished;
|
|
341
|
+
return {
|
|
342
|
+
"@context": CONTEXT,
|
|
343
|
+
"@type": input.type ?? "Article",
|
|
344
|
+
headline: input.headline,
|
|
345
|
+
url: input.url,
|
|
346
|
+
mainEntityOfPage: input.url,
|
|
347
|
+
...(input.description ? { description: input.description } : {}),
|
|
348
|
+
...(input.authors?.length
|
|
349
|
+
? {
|
|
350
|
+
author: input.authors.map((author) => ({
|
|
351
|
+
"@type": "Person" as const,
|
|
352
|
+
name: author.name,
|
|
353
|
+
...(author.url ? { url: author.url } : {}),
|
|
354
|
+
})),
|
|
355
|
+
}
|
|
356
|
+
: {}),
|
|
357
|
+
...(input.publisher ? { publisher: organizationNode(input.publisher) } : {}),
|
|
358
|
+
...(input.datePublished ? { datePublished: input.datePublished } : {}),
|
|
359
|
+
...(dateModified ? { dateModified } : {}),
|
|
360
|
+
...(input.image ? { image: input.image } : {}),
|
|
361
|
+
...(input.keywords?.length ? { keywords: input.keywords } : {}),
|
|
362
|
+
...input.extra,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// --- Person ----------------------------------------------------------------
|
|
367
|
+
|
|
368
|
+
export interface PersonInput extends WithExtra {
|
|
369
|
+
name: string;
|
|
370
|
+
/** Absolute URL of the person's page/profile. */
|
|
371
|
+
url?: string;
|
|
372
|
+
jobTitle?: string;
|
|
373
|
+
/** Employer: an Organization, or just its name. */
|
|
374
|
+
worksFor?: OrganizationInput | string;
|
|
375
|
+
/** Absolute URL of a portrait image. */
|
|
376
|
+
image?: string;
|
|
377
|
+
description?: string;
|
|
378
|
+
email?: string;
|
|
379
|
+
/** Profile/social URLs that corroborate the person. */
|
|
380
|
+
sameAs?: string[];
|
|
381
|
+
/** Home location place name, e.g. "Brussels, Belgium". */
|
|
382
|
+
homeLocation?: string;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export type PersonNode = {
|
|
386
|
+
"@type": "Person";
|
|
387
|
+
name: string;
|
|
388
|
+
url?: string;
|
|
389
|
+
jobTitle?: string;
|
|
390
|
+
worksFor?: OrganizationNode;
|
|
391
|
+
image?: string;
|
|
392
|
+
description?: string;
|
|
393
|
+
email?: string;
|
|
394
|
+
sameAs?: string[];
|
|
395
|
+
homeLocation?: { "@type": "Place"; name: string };
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/** Person: identifies an individual as an entity (portfolio, team, author bios). */
|
|
399
|
+
export function person(input: PersonInput): WithContext<PersonNode> {
|
|
400
|
+
const worksFor =
|
|
401
|
+
typeof input.worksFor === "string"
|
|
402
|
+
? organizationNode({ name: input.worksFor })
|
|
403
|
+
: input.worksFor
|
|
404
|
+
? organizationNode(input.worksFor)
|
|
405
|
+
: undefined;
|
|
406
|
+
return {
|
|
407
|
+
"@context": CONTEXT,
|
|
408
|
+
"@type": "Person",
|
|
409
|
+
name: input.name,
|
|
410
|
+
...(input.url ? { url: input.url } : {}),
|
|
411
|
+
...(input.jobTitle ? { jobTitle: input.jobTitle } : {}),
|
|
412
|
+
...(worksFor ? { worksFor } : {}),
|
|
413
|
+
...(input.image ? { image: input.image } : {}),
|
|
414
|
+
...(input.description ? { description: input.description } : {}),
|
|
415
|
+
...(input.email ? { email: input.email } : {}),
|
|
416
|
+
...(input.sameAs?.length ? { sameAs: input.sameAs } : {}),
|
|
417
|
+
...(input.homeLocation
|
|
418
|
+
? { homeLocation: { "@type": "Place" as const, name: input.homeLocation } }
|
|
419
|
+
: {}),
|
|
420
|
+
...input.extra,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// --- LocalBusiness ---------------------------------------------------------
|
|
425
|
+
|
|
426
|
+
export interface PostalAddressInput {
|
|
427
|
+
streetAddress?: string;
|
|
428
|
+
addressLocality?: string;
|
|
429
|
+
addressRegion?: string;
|
|
430
|
+
postalCode?: string;
|
|
431
|
+
/** ISO country code, e.g. "BE". */
|
|
432
|
+
addressCountry?: string;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface GeoInput {
|
|
436
|
+
latitude: number;
|
|
437
|
+
longitude: number;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export interface AggregateRatingInput {
|
|
441
|
+
ratingValue: string | number;
|
|
442
|
+
reviewCount: string | number;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface LocalBusinessInput extends WithExtra {
|
|
446
|
+
name: string;
|
|
447
|
+
/** Absolute URL of the business site. */
|
|
448
|
+
url?: string;
|
|
449
|
+
description?: string;
|
|
450
|
+
/** Absolute image URL(s). */
|
|
451
|
+
image?: string | string[];
|
|
452
|
+
/** Absolute logo URL. */
|
|
453
|
+
logo?: string;
|
|
454
|
+
email?: string;
|
|
455
|
+
telephone?: string;
|
|
456
|
+
/** e.g. "€€". */
|
|
457
|
+
priceRange?: string;
|
|
458
|
+
openingHours?: string | string[];
|
|
459
|
+
address?: PostalAddressInput;
|
|
460
|
+
geo?: GeoInput;
|
|
461
|
+
/** Map deep-link URL. */
|
|
462
|
+
hasMap?: string;
|
|
463
|
+
aggregateRating?: AggregateRatingInput;
|
|
464
|
+
sameAs?: string[];
|
|
465
|
+
/** schema.org LocalBusiness subtype, e.g. "Store", "ArtGallery". Default "LocalBusiness". */
|
|
466
|
+
type?: string;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export type GeoCoordinatesNode = {
|
|
470
|
+
"@type": "GeoCoordinates";
|
|
471
|
+
latitude: number;
|
|
472
|
+
longitude: number;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
export type AggregateRatingNode = {
|
|
476
|
+
"@type": "AggregateRating";
|
|
477
|
+
ratingValue: string;
|
|
478
|
+
reviewCount: string;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
export type LocalBusinessNode = {
|
|
482
|
+
/** "LocalBusiness" or the subtype passed as `type`. */
|
|
483
|
+
"@type": string;
|
|
484
|
+
name: string;
|
|
485
|
+
url?: string;
|
|
486
|
+
description?: string;
|
|
487
|
+
image?: string[];
|
|
488
|
+
logo?: string;
|
|
489
|
+
email?: string;
|
|
490
|
+
telephone?: string;
|
|
491
|
+
priceRange?: string;
|
|
492
|
+
openingHours?: string | string[];
|
|
493
|
+
address?: PostalAddressNode;
|
|
494
|
+
geo?: GeoCoordinatesNode;
|
|
495
|
+
hasMap?: string;
|
|
496
|
+
aggregateRating?: AggregateRatingNode;
|
|
497
|
+
sameAs?: string[];
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
/** LocalBusiness (or a subtype): a physical business for local/maps SEO. */
|
|
501
|
+
export function localBusiness(
|
|
502
|
+
input: LocalBusinessInput,
|
|
503
|
+
): WithContext<LocalBusinessNode> {
|
|
504
|
+
return {
|
|
505
|
+
"@context": CONTEXT,
|
|
506
|
+
"@type": input.type ?? "LocalBusiness",
|
|
507
|
+
name: input.name,
|
|
508
|
+
...(input.url ? { url: input.url } : {}),
|
|
509
|
+
...(input.description ? { description: input.description } : {}),
|
|
510
|
+
...(input.image
|
|
511
|
+
? { image: Array.isArray(input.image) ? input.image : [input.image] }
|
|
512
|
+
: {}),
|
|
513
|
+
...(input.logo ? { logo: input.logo } : {}),
|
|
514
|
+
...(input.email ? { email: input.email } : {}),
|
|
515
|
+
...(input.telephone ? { telephone: input.telephone } : {}),
|
|
516
|
+
...(input.priceRange ? { priceRange: input.priceRange } : {}),
|
|
517
|
+
...(input.openingHours ? { openingHours: input.openingHours } : {}),
|
|
518
|
+
...(input.address
|
|
519
|
+
? { address: { "@type": "PostalAddress", ...input.address } }
|
|
520
|
+
: {}),
|
|
521
|
+
...(input.geo
|
|
522
|
+
? {
|
|
523
|
+
geo: {
|
|
524
|
+
"@type": "GeoCoordinates",
|
|
525
|
+
latitude: input.geo.latitude,
|
|
526
|
+
longitude: input.geo.longitude,
|
|
527
|
+
},
|
|
528
|
+
}
|
|
529
|
+
: {}),
|
|
530
|
+
...(input.hasMap ? { hasMap: input.hasMap } : {}),
|
|
531
|
+
...(input.aggregateRating
|
|
532
|
+
? {
|
|
533
|
+
aggregateRating: {
|
|
534
|
+
"@type": "AggregateRating",
|
|
535
|
+
ratingValue: String(input.aggregateRating.ratingValue),
|
|
536
|
+
reviewCount: String(input.aggregateRating.reviewCount),
|
|
537
|
+
},
|
|
538
|
+
}
|
|
539
|
+
: {}),
|
|
540
|
+
...(input.sameAs?.length ? { sameAs: input.sameAs } : {}),
|
|
541
|
+
...input.extra,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// --- Event -----------------------------------------------------------------
|
|
546
|
+
|
|
547
|
+
export interface EventLocationInput {
|
|
548
|
+
name?: string;
|
|
549
|
+
/** Postal address string or a URL for online events. */
|
|
550
|
+
address?: string;
|
|
551
|
+
/** Absolute URL (physical place page or online joining link). */
|
|
552
|
+
url?: string;
|
|
553
|
+
/** Set true for a fully virtual event (emits VirtualLocation). */
|
|
554
|
+
online?: boolean;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export interface EventInput extends WithExtra {
|
|
558
|
+
name: string;
|
|
559
|
+
/** ISO 8601 start, e.g. "2026-09-30" or "2026-09-30T09:00:00+02:00". */
|
|
560
|
+
startDate: string;
|
|
561
|
+
/** ISO 8601 end. Defaults to startDate. */
|
|
562
|
+
endDate?: string;
|
|
563
|
+
description?: string;
|
|
564
|
+
/** Absolute URL of the event page. */
|
|
565
|
+
url?: string;
|
|
566
|
+
/** Absolute image URL(s). */
|
|
567
|
+
image?: string | string[];
|
|
568
|
+
location?: EventLocationInput;
|
|
569
|
+
organizer?: OrganizationInput;
|
|
570
|
+
offers?: OfferInput;
|
|
571
|
+
/** Defaults to "https://schema.org/EventScheduled". */
|
|
572
|
+
eventStatus?: string;
|
|
573
|
+
attendanceMode?: "offline" | "online" | "mixed";
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export type PlaceNode = {
|
|
577
|
+
"@type": "Place";
|
|
578
|
+
name?: string;
|
|
579
|
+
address?: string;
|
|
580
|
+
url?: string;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
export type VirtualLocationNode = { "@type": "VirtualLocation"; url?: string };
|
|
584
|
+
|
|
585
|
+
export type EventNode = {
|
|
586
|
+
"@type": "Event";
|
|
587
|
+
name: string;
|
|
588
|
+
startDate: string;
|
|
589
|
+
endDate: string;
|
|
590
|
+
eventStatus: string;
|
|
591
|
+
eventAttendanceMode?: string;
|
|
592
|
+
description?: string;
|
|
593
|
+
url?: string;
|
|
594
|
+
image?: string[];
|
|
595
|
+
location?: PlaceNode | VirtualLocationNode;
|
|
596
|
+
organizer?: OrganizationNode;
|
|
597
|
+
offers?: OfferNode | AggregateOfferNode;
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
const ATTENDANCE_MODE: Record<NonNullable<EventInput["attendanceMode"]>, string> = {
|
|
601
|
+
offline: "https://schema.org/OfflineEventAttendanceMode",
|
|
602
|
+
online: "https://schema.org/OnlineEventAttendanceMode",
|
|
603
|
+
mixed: "https://schema.org/MixedEventAttendanceMode",
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
function eventLocationNode(
|
|
607
|
+
location: EventLocationInput,
|
|
608
|
+
): PlaceNode | VirtualLocationNode {
|
|
609
|
+
if (location.online) {
|
|
610
|
+
return {
|
|
611
|
+
"@type": "VirtualLocation",
|
|
612
|
+
...(location.url ? { url: location.url } : {}),
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
"@type": "Place",
|
|
617
|
+
...(location.name ? { name: location.name } : {}),
|
|
618
|
+
...(location.address ? { address: location.address } : {}),
|
|
619
|
+
...(location.url ? { url: location.url } : {}),
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** Event: a scheduled happening (summit, workshop, conference) for event rich results. */
|
|
624
|
+
export function event(input: EventInput): WithContext<EventNode> {
|
|
625
|
+
return {
|
|
626
|
+
"@context": CONTEXT,
|
|
627
|
+
"@type": "Event",
|
|
628
|
+
name: input.name,
|
|
629
|
+
startDate: input.startDate,
|
|
630
|
+
endDate: input.endDate ?? input.startDate,
|
|
631
|
+
eventStatus: input.eventStatus ?? "https://schema.org/EventScheduled",
|
|
632
|
+
...(input.attendanceMode
|
|
633
|
+
? { eventAttendanceMode: ATTENDANCE_MODE[input.attendanceMode] }
|
|
634
|
+
: {}),
|
|
635
|
+
...(input.description ? { description: input.description } : {}),
|
|
636
|
+
...(input.url ? { url: input.url } : {}),
|
|
637
|
+
...(input.image
|
|
638
|
+
? { image: Array.isArray(input.image) ? input.image : [input.image] }
|
|
639
|
+
: {}),
|
|
640
|
+
...(input.location ? { location: eventLocationNode(input.location) } : {}),
|
|
641
|
+
...(input.organizer ? { organizer: organizationNode(input.organizer) } : {}),
|
|
642
|
+
...(input.offers ? { offers: offerNode(input.offers) } : {}),
|
|
643
|
+
...input.extra,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// --- Dataset ---------------------------------------------------------------
|
|
648
|
+
|
|
649
|
+
export interface DataDownloadInput {
|
|
650
|
+
/** Absolute URL of the file/endpoint. */
|
|
651
|
+
contentUrl: string;
|
|
652
|
+
/** IANA media type or a format name, e.g. "text/csv", "application/json". */
|
|
653
|
+
encodingFormat?: string;
|
|
654
|
+
name?: string;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export interface DatasetInput extends WithExtra {
|
|
658
|
+
name: string;
|
|
659
|
+
description: string;
|
|
660
|
+
/** Absolute URL of the dataset's landing page. */
|
|
661
|
+
url?: string;
|
|
662
|
+
/** Stable identifier(s): DOI, URI, registry code. */
|
|
663
|
+
identifier?: string | string[];
|
|
664
|
+
/** License URL, e.g. "https://creativecommons.org/licenses/by/4.0/". */
|
|
665
|
+
license?: string;
|
|
666
|
+
keywords?: string[];
|
|
667
|
+
/** BCP 47 language tag(s) of the dataset's contents. */
|
|
668
|
+
inLanguage?: string | string[];
|
|
669
|
+
/** ISO 8601 interval, e.g. "2008-01-01/2025-12-31". */
|
|
670
|
+
temporalCoverage?: string;
|
|
671
|
+
/** Place name or ISO country code the data covers. */
|
|
672
|
+
spatialCoverage?: string;
|
|
673
|
+
dateModified?: string;
|
|
674
|
+
/** Downloadable distributions of the data. */
|
|
675
|
+
distribution?: DataDownloadInput[];
|
|
676
|
+
/** Google shows a free-access badge; omit rather than guess. */
|
|
677
|
+
isAccessibleForFree?: boolean;
|
|
678
|
+
creator?: OrganizationInput;
|
|
679
|
+
publisher?: OrganizationInput;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export type DataDownloadNode = {
|
|
683
|
+
"@type": "DataDownload";
|
|
684
|
+
contentUrl: string;
|
|
685
|
+
encodingFormat?: string;
|
|
686
|
+
name?: string;
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
export type DatasetNode = {
|
|
690
|
+
"@type": "Dataset";
|
|
691
|
+
name: string;
|
|
692
|
+
description: string;
|
|
693
|
+
url?: string;
|
|
694
|
+
identifier?: string | string[];
|
|
695
|
+
license?: string;
|
|
696
|
+
keywords?: string[];
|
|
697
|
+
inLanguage?: string | string[];
|
|
698
|
+
temporalCoverage?: string;
|
|
699
|
+
spatialCoverage?: string;
|
|
700
|
+
dateModified?: string;
|
|
701
|
+
distribution?: DataDownloadNode[];
|
|
702
|
+
isAccessibleForFree?: boolean;
|
|
703
|
+
creator?: OrganizationNode;
|
|
704
|
+
publisher?: OrganizationNode;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
/** Dataset: a published data collection, for Google's dataset search. */
|
|
708
|
+
export function dataset(input: DatasetInput): WithContext<DatasetNode> {
|
|
709
|
+
return {
|
|
710
|
+
"@context": CONTEXT,
|
|
711
|
+
"@type": "Dataset",
|
|
712
|
+
name: input.name,
|
|
713
|
+
description: input.description,
|
|
714
|
+
...(input.url ? { url: input.url } : {}),
|
|
715
|
+
...(input.identifier ? { identifier: input.identifier } : {}),
|
|
716
|
+
...(input.license ? { license: input.license } : {}),
|
|
717
|
+
...(input.keywords?.length ? { keywords: input.keywords } : {}),
|
|
718
|
+
...(input.inLanguage ? { inLanguage: input.inLanguage } : {}),
|
|
719
|
+
...(input.temporalCoverage ? { temporalCoverage: input.temporalCoverage } : {}),
|
|
720
|
+
...(input.spatialCoverage ? { spatialCoverage: input.spatialCoverage } : {}),
|
|
721
|
+
...(input.dateModified ? { dateModified: input.dateModified } : {}),
|
|
722
|
+
...(input.distribution?.length
|
|
723
|
+
? {
|
|
724
|
+
distribution: input.distribution.map((item) => ({
|
|
725
|
+
"@type": "DataDownload" as const,
|
|
726
|
+
contentUrl: item.contentUrl,
|
|
727
|
+
...(item.encodingFormat
|
|
728
|
+
? { encodingFormat: item.encodingFormat }
|
|
729
|
+
: {}),
|
|
730
|
+
...(item.name ? { name: item.name } : {}),
|
|
731
|
+
})),
|
|
732
|
+
}
|
|
733
|
+
: {}),
|
|
734
|
+
...(input.isAccessibleForFree !== undefined
|
|
735
|
+
? { isAccessibleForFree: input.isAccessibleForFree }
|
|
736
|
+
: {}),
|
|
737
|
+
...(input.creator ? { creator: organizationNode(input.creator) } : {}),
|
|
738
|
+
...(input.publisher ? { publisher: organizationNode(input.publisher) } : {}),
|
|
739
|
+
...input.extra,
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// --- DefinedTerm / DefinedTermSet -------------------------------------------
|
|
744
|
+
|
|
745
|
+
export interface DefinedTermSetInput extends WithExtra {
|
|
746
|
+
name: string;
|
|
747
|
+
/** Absolute URL of the set's landing page. */
|
|
748
|
+
url?: string;
|
|
749
|
+
description?: string;
|
|
750
|
+
/** Version/edition of the vocabulary, e.g. "2025". */
|
|
751
|
+
version?: string;
|
|
752
|
+
inLanguage?: string | string[];
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
export type DefinedTermSetNode = {
|
|
756
|
+
"@type": "DefinedTermSet";
|
|
757
|
+
name: string;
|
|
758
|
+
url?: string;
|
|
759
|
+
description?: string;
|
|
760
|
+
version?: string;
|
|
761
|
+
inLanguage?: string | string[];
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
/** DefinedTermSet node without `@context`, for embedding as inDefinedTermSet. */
|
|
765
|
+
function definedTermSetNode(input: DefinedTermSetInput): DefinedTermSetNode {
|
|
766
|
+
return {
|
|
767
|
+
"@type": "DefinedTermSet",
|
|
768
|
+
name: input.name,
|
|
769
|
+
...(input.url ? { url: input.url } : {}),
|
|
770
|
+
...(input.description ? { description: input.description } : {}),
|
|
771
|
+
...(input.version ? { version: input.version } : {}),
|
|
772
|
+
...(input.inLanguage ? { inLanguage: input.inLanguage } : {}),
|
|
773
|
+
...input.extra,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** DefinedTermSet: the vocabulary/classification a term belongs to. */
|
|
778
|
+
export function definedTermSet(
|
|
779
|
+
input: DefinedTermSetInput,
|
|
780
|
+
): WithContext<DefinedTermSetNode> {
|
|
781
|
+
return { "@context": CONTEXT, ...definedTermSetNode(input) };
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
export interface DefinedTermInput extends WithExtra {
|
|
785
|
+
name: string;
|
|
786
|
+
description?: string;
|
|
787
|
+
/** Absolute URL of the term's own page. */
|
|
788
|
+
url?: string;
|
|
789
|
+
/** The code identifying the term inside its set, e.g. "62.01". */
|
|
790
|
+
termCode?: string;
|
|
791
|
+
inLanguage?: string | string[];
|
|
792
|
+
/** The vocabulary this term belongs to — its absolute URL, or a full set. */
|
|
793
|
+
inDefinedTermSet?: string | DefinedTermSetInput;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export type DefinedTermNode = {
|
|
797
|
+
"@type": "DefinedTerm";
|
|
798
|
+
name: string;
|
|
799
|
+
description?: string;
|
|
800
|
+
url?: string;
|
|
801
|
+
termCode?: string;
|
|
802
|
+
inLanguage?: string | string[];
|
|
803
|
+
inDefinedTermSet?: string | DefinedTermSetNode;
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
/** DefinedTerm: one entry of a controlled vocabulary or classification. */
|
|
807
|
+
export function definedTerm(input: DefinedTermInput): WithContext<DefinedTermNode> {
|
|
808
|
+
const set =
|
|
809
|
+
typeof input.inDefinedTermSet === "string"
|
|
810
|
+
? input.inDefinedTermSet
|
|
811
|
+
: input.inDefinedTermSet
|
|
812
|
+
? definedTermSetNode(input.inDefinedTermSet)
|
|
813
|
+
: undefined;
|
|
814
|
+
return {
|
|
815
|
+
"@context": CONTEXT,
|
|
816
|
+
"@type": "DefinedTerm",
|
|
817
|
+
name: input.name,
|
|
818
|
+
...(input.description ? { description: input.description } : {}),
|
|
819
|
+
...(input.url ? { url: input.url } : {}),
|
|
820
|
+
...(input.termCode ? { termCode: input.termCode } : {}),
|
|
821
|
+
...(input.inLanguage ? { inLanguage: input.inLanguage } : {}),
|
|
822
|
+
...(set ? { inDefinedTermSet: set } : {}),
|
|
823
|
+
...input.extra,
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// --- Factory ---------------------------------------------------------------
|
|
828
|
+
|
|
829
|
+
export interface SeoConfig {
|
|
830
|
+
/** Absolute site origin, e.g. "https://acme.example". */
|
|
831
|
+
baseUrl: string;
|
|
832
|
+
/**
|
|
833
|
+
* Shared publisher/provider, injected into article()/website()/organization().
|
|
834
|
+
* Its `url` and `logo` may be site-relative — they are resolved against
|
|
835
|
+
* `baseUrl`.
|
|
836
|
+
*/
|
|
837
|
+
organization?: OrganizationInput;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** A path-aware version of a crumb: `path` is resolved against the base URL. */
|
|
841
|
+
export interface BreadcrumbPath {
|
|
842
|
+
name: string;
|
|
843
|
+
path: string;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Binds the builders to a site so callers pass site-relative paths instead of
|
|
848
|
+
* absolute URLs, and the configured Organization is injected automatically.
|
|
849
|
+
* Nested URL fields (`organization.url`/`logo`, `offers.url`, article `image`)
|
|
850
|
+
* are resolved too — JSON-LD must never ship relative URLs.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* const seo = createSeo({ baseUrl: getServerUrl(), organization: ORG });
|
|
854
|
+
* <JsonLd data={seo.article({ path: `/blog/${slug}`, headline, datePublished })} />
|
|
855
|
+
*/
|
|
856
|
+
export function createSeo(config: SeoConfig) {
|
|
857
|
+
const absolute = (path: string): string => absoluteUrl(path, config.baseUrl);
|
|
858
|
+
|
|
859
|
+
const resolveOrg = (org: OrganizationInput): OrganizationInput => ({
|
|
860
|
+
...org,
|
|
861
|
+
...(org.url ? { url: absolute(org.url) } : {}),
|
|
862
|
+
...(org.logo ? { logo: absolute(org.logo) } : {}),
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
const resolveOffers = (offers: OfferInput): OfferInput => ({
|
|
866
|
+
...offers,
|
|
867
|
+
...(offers.url ? { url: absolute(offers.url) } : {}),
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
return {
|
|
871
|
+
/** Resolve a site-relative path to an absolute URL. */
|
|
872
|
+
absolute,
|
|
873
|
+
/** FAQPage (path-free). */
|
|
874
|
+
faqPage,
|
|
875
|
+
/** BreadcrumbList from site-relative paths. */
|
|
876
|
+
breadcrumbs(items: BreadcrumbPath[]): WithContext<BreadcrumbListNode> {
|
|
877
|
+
return breadcrumbList(
|
|
878
|
+
items.map((item) => ({ name: item.name, url: absolute(item.path) })),
|
|
879
|
+
);
|
|
880
|
+
},
|
|
881
|
+
/** Organization from config (with optional per-call overrides). */
|
|
882
|
+
organization(
|
|
883
|
+
overrides?: Partial<OrganizationInput>,
|
|
884
|
+
): WithContext<OrganizationNode> {
|
|
885
|
+
if (!config.organization) {
|
|
886
|
+
throw new Error(
|
|
887
|
+
"createSeo: organization() needs `organization` in config",
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
return organization(resolveOrg({ ...config.organization, ...overrides }));
|
|
891
|
+
},
|
|
892
|
+
/** WebSite from config, defaulting name/url/publisher to the configured org. */
|
|
893
|
+
website(input?: Partial<WebsiteInput>): WithContext<WebsiteNode> {
|
|
894
|
+
const name = input?.name ?? config.organization?.name;
|
|
895
|
+
if (!name) {
|
|
896
|
+
throw new Error(
|
|
897
|
+
"createSeo: website() needs a name or configured organization",
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
const publisher = input?.publisher ?? config.organization;
|
|
901
|
+
return website({
|
|
902
|
+
name,
|
|
903
|
+
url: absolute(input?.url ?? config.baseUrl),
|
|
904
|
+
...(publisher ? { publisher: resolveOrg(publisher) } : {}),
|
|
905
|
+
});
|
|
906
|
+
},
|
|
907
|
+
/** SoftwareApplication; `path` (default "/") and `offers.url` are resolved. */
|
|
908
|
+
softwareApplication(
|
|
909
|
+
input: Omit<SoftwareApplicationInput, "url"> & { path?: string },
|
|
910
|
+
): WithContext<SoftwareApplicationNode> {
|
|
911
|
+
const { path, offers, ...rest } = input;
|
|
912
|
+
return softwareApplication({
|
|
913
|
+
...rest,
|
|
914
|
+
url: absolute(path ?? "/"),
|
|
915
|
+
...(offers ? { offers: resolveOffers(offers) } : {}),
|
|
916
|
+
});
|
|
917
|
+
},
|
|
918
|
+
/** Article; `path`/`image` are resolved and the configured org becomes publisher. */
|
|
919
|
+
article(
|
|
920
|
+
input: Omit<ArticleInput, "url" | "image" | "publisher"> & {
|
|
921
|
+
path: string;
|
|
922
|
+
image?: string;
|
|
923
|
+
publisher?: OrganizationInput;
|
|
924
|
+
},
|
|
925
|
+
): WithContext<ArticleNode> {
|
|
926
|
+
const { path, image, publisher, ...rest } = input;
|
|
927
|
+
const resolvedPublisher = publisher ?? config.organization;
|
|
928
|
+
return article({
|
|
929
|
+
...rest,
|
|
930
|
+
url: absolute(path),
|
|
931
|
+
...(image ? { image: absolute(image) } : {}),
|
|
932
|
+
...(resolvedPublisher
|
|
933
|
+
? { publisher: resolveOrg(resolvedPublisher) }
|
|
934
|
+
: {}),
|
|
935
|
+
});
|
|
936
|
+
},
|
|
937
|
+
/** Dataset; `path` is resolved and the configured org becomes publisher. */
|
|
938
|
+
dataset(
|
|
939
|
+
input: Omit<DatasetInput, "url" | "publisher"> & {
|
|
940
|
+
path?: string;
|
|
941
|
+
publisher?: OrganizationInput;
|
|
942
|
+
},
|
|
943
|
+
): WithContext<DatasetNode> {
|
|
944
|
+
const { path, publisher, ...rest } = input;
|
|
945
|
+
const resolvedPublisher = publisher ?? config.organization;
|
|
946
|
+
return dataset({
|
|
947
|
+
...rest,
|
|
948
|
+
...(path ? { url: absolute(path) } : {}),
|
|
949
|
+
...(resolvedPublisher
|
|
950
|
+
? { publisher: resolveOrg(resolvedPublisher) }
|
|
951
|
+
: {}),
|
|
952
|
+
});
|
|
953
|
+
},
|
|
954
|
+
/** DefinedTerm; `path` and the term set's `path` are resolved. */
|
|
955
|
+
definedTerm(
|
|
956
|
+
input: Omit<DefinedTermInput, "url" | "inDefinedTermSet"> & {
|
|
957
|
+
path?: string;
|
|
958
|
+
inDefinedTermSet?:
|
|
959
|
+
| string
|
|
960
|
+
| (Omit<DefinedTermSetInput, "url"> & { path?: string });
|
|
961
|
+
},
|
|
962
|
+
): WithContext<DefinedTermNode> {
|
|
963
|
+
const { path, inDefinedTermSet, ...rest } = input;
|
|
964
|
+
let set: DefinedTermInput["inDefinedTermSet"];
|
|
965
|
+
if (typeof inDefinedTermSet === "string") {
|
|
966
|
+
set = absolute(inDefinedTermSet);
|
|
967
|
+
} else if (inDefinedTermSet) {
|
|
968
|
+
const { path: setPath, ...setRest } = inDefinedTermSet;
|
|
969
|
+
set = { ...setRest, ...(setPath ? { url: absolute(setPath) } : {}) };
|
|
970
|
+
}
|
|
971
|
+
return definedTerm({
|
|
972
|
+
...rest,
|
|
973
|
+
...(path ? { url: absolute(path) } : {}),
|
|
974
|
+
...(set ? { inDefinedTermSet: set } : {}),
|
|
975
|
+
});
|
|
976
|
+
},
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
export type Seo = ReturnType<typeof createSeo>;
|