@sarimarcus/content-sites-core 0.55.3 → 0.56.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.
@@ -0,0 +1,78 @@
1
+ // Shared article prose and metadata helpers promoted from the sites' src/utils/articleRender.ts (SLA-3720).
2
+ import { parseMarkdownBlock, parseMarkdownInline } from '../text/markdown.ts';
3
+
4
+ /**
5
+ * Splits a markdown body on blank lines (`\n\n+`) and renders each chunk:
6
+ * block-level markdown constructs (lists, blockquotes, tables) use `parseMarkdownBlock`
7
+ * while ordinary prose paragraphs are wrapped in `<p>` via `parseMarkdownInline`.
8
+ */
9
+ export function splitParagraphs(body: string, basePath: string = '/', sourcesLength?: number): string[] {
10
+ return body
11
+ .split(/\n\n+/)
12
+ .map((p) => p.trim())
13
+ .filter(Boolean)
14
+ .map((chunk) => {
15
+ if (/^(?:[-*+]|\d+\.)\s|^>\s|^\|/m.test(chunk)) {
16
+ return parseMarkdownBlock(chunk, basePath, sourcesLength);
17
+ }
18
+ return `<p>${parseMarkdownInline(chunk, basePath, sourcesLength)}</p>`;
19
+ });
20
+ }
21
+
22
+ /**
23
+ * Inline markdown to HTML with footnote conversion (`[^N]` → `<sup><a href="#fn-N">[N]</a></sup>`),
24
+ * used by `Interlude.astro` and `ArticleKeyFacts.astro`.
25
+ */
26
+ export function renderInlineMarkdown(text: string, basePath: string = '/', sourcesLength?: number): string {
27
+ return parseMarkdownInline(text, basePath, sourcesLength);
28
+ }
29
+
30
+ /**
31
+ * Normalizes a `YYYY-MM-DD` date string (or ISO string) into a full ISO-8601 timestamp with timezone offset
32
+ * in `timeZone` (defaults to `'Europe/Madrid'`).
33
+ */
34
+ export function toISO(dateStr: string | undefined, timeZone: string = 'Europe/Madrid'): string | undefined {
35
+ if (!dateStr) return undefined;
36
+ if (dateStr.includes('T')) return dateStr;
37
+ const probe = new Date(`${dateStr}T12:00:00Z`);
38
+ const tzPart = new Intl.DateTimeFormat('en-US', {
39
+ timeZone,
40
+ timeZoneName: 'longOffset',
41
+ })
42
+ .formatToParts(probe)
43
+ .find((p) => p.type === 'timeZoneName')?.value;
44
+ const offset = tzPart?.replace(/^GMT/, '') || '+01:00';
45
+ return `${dateStr}T00:00:00${offset}`;
46
+ }
47
+
48
+ export interface AnswerBoxSectionLike {
49
+ interludes?: readonly {
50
+ type: string;
51
+ question?: string;
52
+ answer?: string;
53
+ }[];
54
+ }
55
+
56
+ /**
57
+ * Merges `answer-box` interludes from `sections` into the article's `faqs` list (deduping by lowercase question)
58
+ * so `StructuredData.astro` emits a complete `FAQPage` node matching the visible Q&As on the page.
59
+ */
60
+ export function mergeAnswerBoxFaqs(
61
+ faqs: readonly { question: string; answer: string }[] | undefined,
62
+ sections: readonly AnswerBoxSectionLike[] | undefined,
63
+ ): { question: string; answer: string }[] {
64
+ const base = [...(faqs ?? [])];
65
+ const seen = new Set(base.map((f) => f.question.trim().toLowerCase()));
66
+ for (const s of sections ?? []) {
67
+ for (const item of s.interludes ?? []) {
68
+ if (item.type === 'answer-box' && item.question && item.answer) {
69
+ const key = item.question.trim().toLowerCase();
70
+ if (!seen.has(key)) {
71
+ seen.add(key);
72
+ base.push({ question: item.question, answer: item.answer });
73
+ }
74
+ }
75
+ }
76
+ }
77
+ return base;
78
+ }
@@ -0,0 +1,223 @@
1
+ // Shared Zod collection schema for `articles` (SLA-3715).
2
+ // Parameterised by the site's categories, tags, relatedTargetTypes, interludeConfig, and optional
3
+ // audiences/themes/eras/dossiers/people vocabularies so both travel sites and articles-only editorial
4
+ // sites share one canonical definition without importing travel-only enums.
5
+ import type { z as Zod } from 'astro/zod';
6
+ import { eraSchemaFields, eraYearIssues } from '../eras/index.ts';
7
+ import { createInterludeSchema, INTERLUDE_MAX_PER_SECTION, type InterludeSchemaConfig } from '../interludes/index.ts';
8
+ import type { FieldIssue } from '../internal/issues.ts';
9
+ import { isObject } from '../internal/guards.ts';
10
+ import { ARTICLE_FORMATS, ARTICLE_SHAPE_UNION, articleShapeIssues } from './formats.ts';
11
+
12
+ /** Metadata for a controlled article tag (used in `src/data/articleTags.ts` and `/articles/tag/[tag]` hubs). */
13
+ export interface ArticleTagMeta {
14
+ label: string;
15
+ description: string;
16
+ seoTitle?: string;
17
+ h1?: string;
18
+ }
19
+
20
+ export interface ArticleSchemaOptions {
21
+ /** Mandatory non-empty tuple of category slugs for `/articles/topic/<category>`. */
22
+ categories: readonly [string, ...string[]];
23
+ /** Optional controlled vocabulary of tag slugs for `/articles/tag/<tag>` (1-4 tags per article when set). */
24
+ tags?: readonly [string, ...string[]];
25
+ /** Allowed `relatedContent[].type` values from `src/utils/relatedTargets.ts`. */
26
+ relatedTargetTypes: readonly [string, ...string[]];
27
+ /** Interlude schema config (`scripts/interludes.config.json`). Either `interludeConfig` or `interludeSchema` is required. */
28
+ interludeConfig?: InterludeSchemaConfig;
29
+ /** Pre-built interlude schema if the site constructs `createInterludeSchema` itself. */
30
+ interludeSchema?: unknown;
31
+ /** Optional site audience enum; defaults to optional `z.array(z.string()).max(5)`. */
32
+ audiences?: readonly [string, ...string[]];
33
+ /** Optional site theme enum; defaults to optional `z.array(z.string()).max(4)`. */
34
+ themes?: readonly [string, ...string[]];
35
+ /** Optional historical era IDs (`@sarimarcus/content-sites-core/eras`). */
36
+ eras?: readonly [string, ...string[]];
37
+ /** Optional editorial dossier slugs. */
38
+ dossiers?: readonly [string, ...string[]];
39
+ /** Whether to include `people: z.array(z.string()).optional()` (defaults to true when `eras` is provided). */
40
+ people?: boolean;
41
+ /** Whether `category` is optional on legacy corpora (defaults to false on new sites). */
42
+ optionalCategory?: boolean;
43
+ }
44
+
45
+ type ZodLike = typeof Zod;
46
+
47
+ /**
48
+ * Pure validation issues for an article object's `superRefine` block:
49
+ * - format & section/FAQ count shape rules (`articleShapeIssues`)
50
+ * - historical year ordering (`eraYearIssues`)
51
+ * - `discoverAngle` presence & source URL matching when `editorialMode === 'discover'`
52
+ * - duplicate tag check when `tags` is present
53
+ */
54
+ export function articleSuperRefineIssues(article: unknown): FieldIssue[] {
55
+ if (!isObject(article)) return [{ path: '', message: 'article: expected a JSON object' }];
56
+ const issues: FieldIssue[] = [
57
+ ...articleShapeIssues(article),
58
+ ...eraYearIssues(article),
59
+ ];
60
+
61
+ const discover = article.editorialMode === 'discover';
62
+ const discoverAngle = isObject(article.discoverAngle) ? article.discoverAngle : null;
63
+ if (discover && !discoverAngle) {
64
+ issues.push({ path: 'discoverAngle', message: 'Discover rationale required' });
65
+ }
66
+ if (!discover && article.discoverAngle !== undefined) {
67
+ issues.push({ path: 'discoverAngle', message: 'Only allowed with editorialMode discover' });
68
+ }
69
+ if (discoverAngle && Array.isArray(discoverAngle.evidenceUrls)) {
70
+ const sources = Array.isArray(article.sources) ? article.sources : [];
71
+ const urls = new Set(
72
+ sources.map((s) => (typeof s === 'string' ? s : isObject(s) && typeof s.url === 'string' ? s.url : '')),
73
+ );
74
+ for (const url of discoverAngle.evidenceUrls) {
75
+ if (typeof url === 'string' && !urls.has(url)) {
76
+ issues.push({ path: 'discoverAngle', message: 'Each evidence URL must match an article source' });
77
+ }
78
+ }
79
+ }
80
+
81
+ if (Array.isArray(article.tags)) {
82
+ const seen = new Set<string>();
83
+ for (const tag of article.tags) {
84
+ if (typeof tag === 'string') {
85
+ if (seen.has(tag)) {
86
+ issues.push({ path: 'tags', message: `Duplicate tag "${tag}"` });
87
+ }
88
+ seen.add(tag);
89
+ }
90
+ }
91
+ }
92
+
93
+ return issues;
94
+ }
95
+
96
+ /**
97
+ * Returns the Zod field map for an `articles` collection so a site can spread or extend it,
98
+ * or pass it to `createArticleSchema(z, options)`.
99
+ */
100
+ export function articleSchemaFields(z: ZodLike, options: ArticleSchemaOptions) {
101
+ if (!options.categories.length) {
102
+ throw new Error('articleSchemaFields: categories must be a non-empty tuple');
103
+ }
104
+ if (!options.relatedTargetTypes.length) {
105
+ throw new Error('articleSchemaFields: relatedTargetTypes must be a non-empty tuple');
106
+ }
107
+
108
+ const interlude = (options.interludeSchema ??
109
+ (options.interludeConfig ? createInterludeSchema(z, options.interludeConfig) : null)) as Zod.ZodTypeAny | null;
110
+ if (!interlude) {
111
+ throw new Error('articleSchemaFields: either interludeConfig or interludeSchema is required');
112
+ }
113
+
114
+ const keyFactsSchema = z.array(z.object({
115
+ figure: z.string().min(1).max(14),
116
+ label: z.string().min(1).max(28),
117
+ detail: z.string().min(1).max(90),
118
+ })).min(ARTICLE_SHAPE_UNION.keyFacts[0]).max(ARTICLE_SHAPE_UNION.keyFacts[1]).optional();
119
+
120
+ const sourcesSchema = z.array(z.union([
121
+ z.string().url(),
122
+ z.object({
123
+ url: z.string().url(),
124
+ name: z.string().optional(),
125
+ quote: z.string().min(1),
126
+ }),
127
+ ])).optional();
128
+
129
+ const relatedContentSchema = z.array(z.object({
130
+ type: z.enum(options.relatedTargetTypes),
131
+ slug: z.string(),
132
+ })).optional();
133
+
134
+ const audiencesSchema = options.audiences?.length
135
+ ? z.array(z.enum(options.audiences)).max(5).optional()
136
+ : z.array(z.string()).max(5).optional();
137
+
138
+ const themesSchema = options.themes?.length
139
+ ? z.array(z.enum(options.themes)).max(4).optional()
140
+ : z.array(z.string()).max(4).optional();
141
+
142
+ const categorySchema = options.optionalCategory
143
+ ? z.enum(options.categories).optional()
144
+ : z.enum(options.categories);
145
+
146
+ const tagsField = options.tags?.length
147
+ ? { tags: z.array(z.enum(options.tags)).min(1).max(4).optional() }
148
+ : { tags: z.array(z.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/)).min(1).max(4).optional() };
149
+
150
+ const includePeople = options.people ?? Boolean(options.eras?.length);
151
+
152
+ return {
153
+ slug: z.string(),
154
+ ...(includePeople ? { people: z.array(z.string()).optional() } : {}),
155
+ title: z.string().max(65),
156
+ seoTitle: z.string(),
157
+ description: z.string(),
158
+ intro: z.string(),
159
+ keyFacts: keyFactsSchema,
160
+ targetKeyword: z.string(),
161
+ editorialMode: z.enum(['evergreen', 'discover']).optional(),
162
+ editorialFormat: z.enum(ARTICLE_FORMATS).optional(),
163
+ discoverAngle: z.object({
164
+ audience: z.string().trim().min(1),
165
+ hook: z.string().trim().min(1),
166
+ payoff: z.string().trim().min(1),
167
+ evidenceUrls: z.array(z.string().url().refine((url) => url.startsWith('https:'), 'HTTPS URL required')).min(1),
168
+ }).optional(),
169
+ sections: z.array(z.object({
170
+ heading: z.string(),
171
+ body: z.string(),
172
+ subsections: z.array(z.object({
173
+ heading: z.string(),
174
+ body: z.string(),
175
+ })).max(3).optional(),
176
+ interludes: z.array(interlude as Zod.ZodType<{ type: string; afterParagraph?: number } & Record<string, unknown>>).max(INTERLUDE_MAX_PER_SECTION).optional(),
177
+ inlineImages: z.array(z.object({
178
+ slug: z.string(),
179
+ alt: z.string(),
180
+ caption: z.string().optional(),
181
+ afterParagraph: z.number().int().min(0),
182
+ })).max(2).optional(),
183
+ affiliateCarousels: z.array(z.object({
184
+ ids: z.array(z.number().int()).min(1).max(4).optional(),
185
+ afterParagraph: z.number().int().min(0),
186
+ heading: z.string().min(1).max(60).optional(),
187
+ })).max(1).optional(),
188
+ })).min(ARTICLE_SHAPE_UNION.sections[0]).max(ARTICLE_SHAPE_UNION.sections[1]),
189
+ faqs: z.array(z.object({
190
+ question: z.string(),
191
+ answer: z.string(),
192
+ })).max(ARTICLE_SHAPE_UNION.faqs[1]),
193
+ image: z.string().optional(),
194
+ imageAlt: z.string(),
195
+ imageTitle: z.string().optional(),
196
+ semanticField: z.array(z.string()).min(3),
197
+ audiences: audiencesSchema,
198
+ category: categorySchema,
199
+ ...tagsField,
200
+ themes: themesSchema,
201
+ ...(options.dossiers?.length ? { dossiers: z.array(z.enum(options.dossiers)).max(2).optional() } : {}),
202
+ ...(options.eras?.length ? eraSchemaFields(z, options.eras) : {}),
203
+ relatedContent: relatedContentSchema,
204
+ sources: sourcesSchema,
205
+ affiliates: z.object({
206
+ amazonProductIds: z.array(z.string()).optional(),
207
+ }).optional(),
208
+ author: z.string(),
209
+ datePublished: z.string(),
210
+ dateModified: z.string(),
211
+ };
212
+ }
213
+
214
+ /**
215
+ * Full `z.object(...).superRefine(...)` schema for an `articles` collection.
216
+ */
217
+ export function createArticleSchema(z: ZodLike, options: ArticleSchemaOptions) {
218
+ return z.object(articleSchemaFields(z, options)).superRefine((article, ctx) => {
219
+ for (const { path, message } of articleSuperRefineIssues(article)) {
220
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: path ? [path] : [], message });
221
+ }
222
+ });
223
+ }
@@ -43,12 +43,14 @@ const nonEmpty = (values: readonly string[], field: string): [string, ...string[
43
43
  */
44
44
  export function createInterludeSchema(z: ZodBuilders, config: InterludeSchemaConfig) {
45
45
  const relatedCardTypes = nonEmpty(config.relatedCardTypes, 'relatedCardTypes');
46
- const featureTypes = nonEmpty(config.featureTypes.types, 'featureTypes.types');
46
+ const featureTypes = config.featureTypes.types.length
47
+ ? (config.featureTypes.types as [string, ...string[]])
48
+ : null;
47
49
  const after = z.number().int().min(0);
48
50
  const cited = (field: string) =>
49
51
  z.string().min(1).max(260).regex(/\[\^\d+\]\s*$/, `${field} must end with a [^N] citation marker`);
50
52
 
51
- return z.discriminatedUnion('type', [
53
+ const baseVariants = [
52
54
  z.object({
53
55
  type: z.literal('quote'),
54
56
  variant: z.enum(['pull', 'external']),
@@ -103,16 +105,22 @@ export function createInterludeSchema(z: ZodBuilders, config: InterludeSchemaCon
103
105
  rows: z.array(z.array(z.string())).min(2),
104
106
  afterParagraph: after,
105
107
  }),
106
- // The mandatory mid-article feature: despite the name, any entity with its own page. Without a pinned slug the
107
- // template auto-selects it and injects relatedType/relatedSlug.
108
- z.object({
109
- type: z.literal('monument-feature'),
110
- ...(config.featureTypes.allowPinnedSlug ? { relatedSlug: z.string().optional() } : {}),
111
- relatedType: z.enum(featureTypes),
112
- afterParagraph: after,
113
- }),
108
+ ...(featureTypes
109
+ ? [
110
+ // The mandatory mid-article feature: despite the name, any entity with its own page. Without a pinned slug the
111
+ // template auto-selects it and injects relatedType/relatedSlug.
112
+ z.object({
113
+ type: z.literal('monument-feature'),
114
+ ...(config.featureTypes.allowPinnedSlug ? { relatedSlug: z.string().optional() } : {}),
115
+ relatedType: z.enum(featureTypes),
116
+ afterParagraph: after,
117
+ }),
118
+ ]
119
+ : []),
114
120
  z.object({ type: z.literal('article-feature'), afterParagraph: after }),
115
- ]);
121
+ ] as const;
122
+
123
+ return z.discriminatedUnion('type', baseVariants as unknown as [typeof baseVariants[0], ...typeof baseVariants[number][]]);
116
124
  }
117
125
 
118
126
  export { pickBandSlot } from './bandSlot.ts';
@@ -235,3 +235,48 @@ export function createPeople<P extends PersonData, I = unknown>(options: {
235
235
  const personPortrait = (slug: string): I | undefined => (portraits as Record<string, I>)[slug];
236
236
  return { toPersonLink, resolvePeople, personPortrait, personHref };
237
237
  }
238
+
239
+ /**
240
+ * Shared Zod field map for an `authors` collection (SLA-3721), covering every field used by
241
+ * `AuthorPage`, `AuthorsIndexPage`, `AuthorStrip`, `ArticleMetadata`, and `personBuilder`.
242
+ */
243
+ export function authorSchemaFields(z: ZodBuilders) {
244
+ return {
245
+ name: z.string().min(1),
246
+ slug: z.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/),
247
+ role: z.string().optional(),
248
+ jobTitle: z.string().max(60, 'jobTitle renders as an eyebrow and Person.jobTitle: max 60 chars.').optional(),
249
+ bio: z.string().min(1),
250
+ description: z.string().optional(),
251
+ credentials: z.string().optional(),
252
+ photo: z.string().optional(),
253
+ socialLinks: z.array(z.string().url()).optional(),
254
+ sameAs: z.array(z.string().url()).optional(),
255
+ expertise: z.array(z.string().max(40, 'expertise entries render as chips: max 40 chars each.')).optional(),
256
+ featured: z.boolean().optional(),
257
+ dateModified: z.string().optional(),
258
+ };
259
+ }
260
+
261
+ export interface AuthorEntryLike<D extends { name: string; slug: string } = { name: string; slug: string }> {
262
+ data: D;
263
+ }
264
+
265
+ /**
266
+ * Resolves a human-readable author `name` (or `slug`) against a loaded `authors` collection,
267
+ * returning the matching entry's `.data` or `null` if unknown.
268
+ */
269
+ export function findAuthorByName<D extends { name: string; slug: string }>(
270
+ authors: readonly (AuthorEntryLike<D> | D)[],
271
+ name: string | undefined | null,
272
+ ): D | null {
273
+ if (!name) return null;
274
+ const target = name.trim().toLowerCase();
275
+ for (const raw of authors) {
276
+ const data = 'data' in raw ? raw.data : raw;
277
+ if (data.name.trim().toLowerCase() === target || data.slug.toLowerCase() === target) {
278
+ return data;
279
+ }
280
+ }
281
+ return null;
282
+ }
@@ -20,8 +20,8 @@ export {
20
20
  export type { DayKey, OpeningHoursInput, OpeningHoursBucket } from './hours.ts';
21
21
  export { openingHoursRows, openingHoursSummary, latestClosing } from './hoursDisplay.ts';
22
22
  export type { OpeningHours, HoursRow } from './hoursDisplay.ts';
23
- export { renderSchemaPolicy } from './policy.ts';
24
- export type { SchemaPolicy } from './policy.ts';
23
+ export { renderSchemaPolicy, profilePageAfterEntries, editorialSchemaPolicy } from './policy.ts';
24
+ export type { SchemaPolicy, EditorialSchemaPolicyOptions } from './policy.ts';
25
25
  export { offer, placeNode, siteOrganizationNode, siteWebsiteNode } from './nodes.ts';
26
26
  export type { OfferFields, SiteNodeFields, OrganizationLogo } from './nodes.ts';
27
27
  export { buildBreadcrumbList, buildWebPageNode, assembleGraph, finalizeGraph } from './graph.ts';
@@ -1,6 +1,12 @@
1
1
  import { temporalCoverageOf } from '../eras/index.ts';
2
2
  import { createSchemaContext } from './context.ts';
3
3
  import { assembleGraph, finalizeGraph, type AssembleOptions, type PageInput } from './graph.ts';
4
+ import { siteOrganizationNode, siteWebsiteNode, type OrganizationLogo, type SiteNodeFields } from './nodes.ts';
5
+ import {
6
+ aboutPageBuilder, articleBuilder, collectionPageBuilder, contactPageBuilder, faqPageBuilder,
7
+ historicalPersonSchema, howToBuilder, itemListBuilder, organizationBuilder, personBuilder,
8
+ type AboutPageOptions, type ArticleOptions, type CollectionPageOptions, type ItemListOptions, type PersonOptions,
9
+ } from './pages.ts';
4
10
  import type { JsonLdNode, SchemaBuilders, SchemaContext, SchemaContextInput, SchemaEntry } from './types.ts';
5
11
 
6
12
  /** A site's JSON-LD policy: its context options, base nodes, builders and graph hooks. */
@@ -11,6 +17,118 @@ export interface SchemaPolicy {
11
17
  hooks?(ctx: SchemaContext, entries: SchemaEntry[]): Pick<AssembleOptions, 'beforeEntries' | 'afterEntries'>;
12
18
  }
13
19
 
20
+ /**
21
+ * Promotes the page's `WebPage` node into `ProfilePage` with `mainEntity` pointing at `${ctx.pageUrl}#person`
22
+ * whenever a `Person` or `HistoricalPerson` node with that `@id` is emitted on the page (SLA-3717).
23
+ */
24
+ export function profilePageAfterEntries(ctx: SchemaContext): NonNullable<AssembleOptions['afterEntries']> {
25
+ return (graph) => {
26
+ const personId = `${ctx.pageUrl}#person`;
27
+ if (graph.some((node) => node['@id'] === personId)) {
28
+ const webPage = graph.find((node) => node['@id'] === ctx.pageUrl);
29
+ if (webPage) {
30
+ webPage['@type'] = 'ProfilePage';
31
+ webPage.mainEntity = { '@id': personId };
32
+ }
33
+ }
34
+ };
35
+ }
36
+
37
+ export interface EditorialSchemaPolicyOptions {
38
+ /** Base Organization + WebSite fields (`name`, `description`, `inLanguage`, plus optional `logo`, `sameAs`, `searchPath`). */
39
+ site: SiteNodeFields & {
40
+ logo?: OrganizationLogo;
41
+ sameAs?: string[];
42
+ searchPath?: string;
43
+ };
44
+ /** Optional `SchemaContextInput` overrides (`inLanguage`, `routes`, `findAuthor`, `publisher`). */
45
+ context?: Partial<SchemaContextInput>;
46
+ article?: ArticleOptions;
47
+ collectionPage?: CollectionPageOptions;
48
+ itemList?: ItemListOptions;
49
+ aboutPage?: AboutPageOptions;
50
+ person?: PersonOptions;
51
+ /** Additional or override builders merged on top of the editorial defaults. */
52
+ extraBuilders?: SchemaBuilders;
53
+ }
54
+
55
+ /**
56
+ * Complete `SchemaPolicy` for an articles-only / editorial site without any tourism vertical dependency (SLA-3717).
57
+ * Includes `Organization`, `WebSite`, `Article`, `CollectionPage`, `ItemList`, `AboutPage`, `ContactPage`, `Person`,
58
+ * `HistoricalPerson`, `FAQPage`, `HowTo`, and the `ProfilePage` `afterEntries` hook.
59
+ */
60
+ export function editorialSchemaPolicy(options: EditorialSchemaPolicyOptions): SchemaPolicy {
61
+ const {
62
+ site,
63
+ context,
64
+ article = { imageVariants: true, defaultSection: 'Article' },
65
+ collectionPage,
66
+ itemList,
67
+ aboutPage,
68
+ person,
69
+ extraBuilders,
70
+ } = options;
71
+
72
+ const { logo, sameAs, searchPath, ...siteFields } = site;
73
+ const faqBuilder = faqPageBuilder();
74
+ const baseBuilders: SchemaBuilders = {
75
+ Article: articleBuilder({ imageVariants: true, defaultSection: 'Article', ...article }),
76
+ article: articleBuilder({ imageVariants: true, defaultSection: 'Article', ...article }),
77
+ CollectionPage: collectionPageBuilder(collectionPage),
78
+ collectionPage: collectionPageBuilder(collectionPage),
79
+ ItemList: itemListBuilder(itemList),
80
+ itemList: itemListBuilder(itemList),
81
+ AboutPage: aboutPageBuilder(aboutPage),
82
+ aboutPage: aboutPageBuilder(aboutPage),
83
+ ContactPage: contactPageBuilder(),
84
+ contactPage: contactPageBuilder(),
85
+ Person: personBuilder(person),
86
+ person: personBuilder(person),
87
+ HistoricalPerson: historicalPersonSchema(),
88
+ historicalPerson: historicalPersonSchema(),
89
+ FAQPage: faqBuilder,
90
+ faqPage: faqBuilder,
91
+ faq: faqBuilder,
92
+ HowTo: howToBuilder(),
93
+ howTo: howToBuilder(),
94
+ Organization: organizationBuilder(),
95
+ organization: organizationBuilder(),
96
+ ...extraBuilders,
97
+ };
98
+
99
+ return {
100
+ ...(context ? { context } : {}),
101
+ nodes: (ctx) => ({
102
+ organization: siteOrganizationNode(
103
+ ctx,
104
+ siteFields,
105
+ logo,
106
+ sameAs?.length ? { sameAs } : {},
107
+ ),
108
+ website: siteWebsiteNode(
109
+ ctx,
110
+ siteFields,
111
+ searchPath
112
+ ? {
113
+ potentialAction: {
114
+ '@type': 'SearchAction',
115
+ target: {
116
+ '@type': 'EntryPoint',
117
+ urlTemplate: `${ctx.siteBaseUrl}${searchPath}?q={search_term_string}`,
118
+ },
119
+ 'query-input': 'required name=search_term_string',
120
+ },
121
+ }
122
+ : {},
123
+ ),
124
+ }),
125
+ builders: baseBuilders,
126
+ hooks: (ctx) => ({
127
+ afterEntries: profilePageAfterEntries(ctx),
128
+ }),
129
+ };
130
+ }
131
+
14
132
  // schema.org defines temporalCoverage on CreativeWork only; a Place node (TouristAttraction) would not validate.
15
133
  const TEMPORAL_TYPES = new Set(['Article']);
16
134
 
package/src/url/routes.ts CHANGED
@@ -2,7 +2,9 @@
2
2
  export const DEFAULT_ROUTES = {
3
3
  articles: 'articles',
4
4
  articleTopic: 'articles/topic',
5
+ articleTag: 'articles/tag',
5
6
  author: 'author',
7
+ authors: 'authors',
6
8
  neighborhood: 'neighborhood',
7
9
  } as const;
8
10