@sarimarcus/content-sites-core 0.54.0 → 0.54.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All packages in the platform release in lockstep; entries are per release version.
4
4
 
5
+ ## 0.54.2 (2026-11-03)
6
+
7
+ - `config`, `dates`, `schema`, `url`: add `SiteConfig.locale` and `getLocale()` (`en-GB` / `it-IT`), locale-aware `formatEditorialDate(iso, locale)` and `relatedZoneLabel(type, lang)`, and dynamic `inLanguage` on JSON-LD `WebSite`, `WebPage`, `CollectionPage`, `Article`, `FAQPage`, and `Event` nodes (SLA-3787).
8
+
9
+ ## 0.54.1 (2026-11-02)
10
+
11
+ - `interludes`: `relocateArticleFeature` no longer falls back to the carousel's section when no back-half section is free. It takes a display section with a slot at least two paragraphs from every block (preferring one without a carousel), then the same search over the whole article, so the card stops stacking on the affiliate carousel. Across the 530 articles with a feature card, those landing within a paragraph of another block drop from 79 to 1.
12
+
5
13
  ## 0.54.0 (2026-11-02)
6
14
 
7
15
  - `interludes`: new `relocateArticleFeature(sections, editorialMode)` and `pickFeatureParagraph(section)`, the build-time move of the `article-feature` card, now skipping sections that hold an affiliate carousel, inline image or interlude and keeping one paragraph of prose between the card and any other block and after it. The three article pages kept identical local copies that ignored carousels and images, so the card could land on the carousel's slot.
@@ -109,6 +109,7 @@ export function sitemapSerialize(lastmodMap, mostRecent, { exclude = [], rules =
109
109
  export function defineSiteConfig(opts) {
110
110
  const rootDir = opts.root instanceof URL ? fileURLToPath(opts.root) : opts.root;
111
111
  const { lastmodMap, mostRecent } = buildLastmodMap(rootDir, opts.lastmod);
112
+ const lang = opts.language ?? 'en';
112
113
  return {
113
114
  ...(opts.redirects ? { redirects: opts.redirects } : {}),
114
115
  site: opts.site,
@@ -116,6 +117,10 @@ export function defineSiteConfig(opts) {
116
117
  output: 'static',
117
118
  trailingSlash: 'never',
118
119
  compressHTML: true,
120
+ i18n: {
121
+ defaultLocale: lang,
122
+ locales: [lang],
123
+ },
119
124
  image: {
120
125
  // Never encodes: serves the committed variants in image-variants/ (npm run images:variants writes them).
121
126
  service: {
@@ -145,7 +150,7 @@ export function defineSiteConfig(opts) {
145
150
  opts.pagefind({
146
151
  indexConfig: {
147
152
  excludeSelectors: [...PAGEFIND_EXCLUDE_SELECTORS],
148
- forceLanguage: opts.language ?? 'en',
153
+ forceLanguage: lang,
149
154
  },
150
155
  }),
151
156
  ],
@@ -22,4 +22,4 @@ export declare function formatDisplayDay(iso: string | undefined, locale?: strin
22
22
  * via `formatUtcDate`: "Aug 12" (single day), "Aug 12–13" (same month),
23
23
  * "May 29 – Jun 5" (cross-month). Returns '' when `start` is missing/invalid.
24
24
  */
25
- export declare function formatUtcDateRange(start?: string, end?: string): string;
25
+ export declare function formatUtcDateRange(start?: string, end?: string, locale?: string): string;
@@ -39,15 +39,15 @@ export function formatDisplayDay(iso, locale = 'en-GB', timeZone = 'UTC') {
39
39
  * via `formatUtcDate`: "Aug 12" (single day), "Aug 12–13" (same month),
40
40
  * "May 29 – Jun 5" (cross-month). Returns '' when `start` is missing/invalid.
41
41
  */
42
- export function formatUtcDateRange(start, end) {
43
- const s = formatUtcDate(start, { month: 'short', day: 'numeric' });
42
+ export function formatUtcDateRange(start, end, locale = 'en-US') {
43
+ const s = formatUtcDate(start, { month: 'short', day: 'numeric' }, locale);
44
44
  if (!s)
45
45
  return '';
46
46
  if (!end || end.length < 10 || end.slice(0, 10) === start.slice(0, 10))
47
47
  return s;
48
- const e = formatUtcDate(end, { month: 'short', day: 'numeric' });
48
+ const e = formatUtcDate(end, { month: 'short', day: 'numeric' }, locale);
49
49
  if (!e)
50
50
  return s;
51
51
  const sameMonth = start.slice(0, 7) === end.slice(0, 7);
52
- return sameMonth ? `${s}–${formatUtcDate(end, { day: 'numeric' })}` : `${s} – ${e}`;
52
+ return sameMonth ? `${s}–${formatUtcDate(end, { day: 'numeric' }, locale)}` : `${s} – ${e}`;
53
53
  }
@@ -9,18 +9,8 @@ interface Section {
9
9
  affiliateCarousels?: Block[];
10
10
  inlineImages?: Block[];
11
11
  }
12
- /**
13
- * Paragraph the feature card goes after: the section's middle, moved to the nearest slot at least two
14
- * paragraphs from any block already in the section (one paragraph of prose between), and never the last
15
- * paragraph when the section has more than one, so prose always follows the card.
16
- */
12
+ /** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
17
13
  export declare function pickFeatureParagraph(section: Section): number;
18
- /**
19
- * Moves the single `article-feature` interlude to its display slot: the last free back-half section
20
- * (or ~40% depth on a Discover piece). A section is free when it holds no interlude, affiliate carousel
21
- * or inline image; with none free it falls back to a section without an interlude, then to the last
22
- * section, and the paragraph pick keeps the card clear of the blocks there. Shared by every site's
23
- * article page and by scripts/validate-articles.mjs, so the gate sees what the reader sees.
24
- */
14
+ /** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
25
15
  export declare function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[];
26
16
  export {};
@@ -1,31 +1,22 @@
1
1
  const paragraphsOf = (s) => (s.body ?? '').split(/\n{2,}/).filter(Boolean).length;
2
2
  const occupied = (s) => [...(s.interludes ?? []), ...(s.affiliateCarousels ?? []), ...(s.inlineImages ?? [])].flatMap((b) => typeof b.afterParagraph === 'number' ? [b.afterParagraph] : []);
3
3
  const isFree = (s) => !(s.interludes?.length || s.affiliateCarousels?.length || s.inlineImages?.length);
4
- /**
5
- * Paragraph the feature card goes after: the section's middle, moved to the nearest slot at least two
6
- * paragraphs from any block already in the section (one paragraph of prose between), and never the last
7
- * paragraph when the section has more than one, so prose always follows the card.
8
- */
4
+ /** Slots at least two paragraphs from every block, so prose sits between; never the last paragraph of a multi-paragraph section. */
5
+ const clearSlots = (section) => {
6
+ const taken = occupied(section);
7
+ const last = Math.max(0, paragraphsOf(section) - 2);
8
+ return Array.from({ length: last + 1 }, (_, p) => p).filter((p) => taken.every((t) => Math.abs(t - p) >= 2));
9
+ };
10
+ /** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
9
11
  export function pickFeatureParagraph(section) {
10
12
  const count = paragraphsOf(section);
11
- const last = Math.max(0, count - 2);
12
13
  const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
13
- const taken = occupied(section);
14
- const ok = (p) => taken.every((t) => Math.abs(t - p) >= 2);
15
- let best = -1;
16
- for (let p = 0; p <= last; p++) {
17
- if (ok(p) && (best < 0 || Math.abs(p - preferred) < Math.abs(best - preferred)))
18
- best = p;
19
- }
20
- return best >= 0 ? best : Math.min(preferred, last);
14
+ const slots = clearSlots(section);
15
+ if (!slots.length)
16
+ return Math.min(preferred, Math.max(0, count - 2));
17
+ return slots.reduce((best, p) => (Math.abs(p - preferred) < Math.abs(best - preferred) ? p : best));
21
18
  }
22
- /**
23
- * Moves the single `article-feature` interlude to its display slot: the last free back-half section
24
- * (or ~40% depth on a Discover piece). A section is free when it holds no interlude, affiliate carousel
25
- * or inline image; with none free it falls back to a section without an interlude, then to the last
26
- * section, and the paragraph pick keeps the card clear of the blocks there. Shared by every site's
27
- * article page and by scripts/validate-articles.mjs, so the gate sees what the reader sees.
28
- */
19
+ /** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
29
20
  export function relocateArticleFeature(sections, editorialMode) {
30
21
  let extracted = null;
31
22
  const stripped = sections.map((section) => ({
@@ -50,8 +41,19 @@ export function relocateArticleFeature(sections, editorialMode) {
50
41
  for (let i = n - 1; i >= Math.ceil(n / 2); i--)
51
42
  order.push(i);
52
43
  }
44
+ const everywhere = Array.from({ length: n }, (_, i) => n - 1 - i);
45
+ const clearAt = stripped.map((section) => clearSlots(section).length > 0);
46
+ const clear = (i) => clearAt[i];
47
+ const noCarousel = (i) => !stripped[i].affiliateCarousels?.length;
53
48
  const noInterlude = (i) => !stripped[i].interludes.length;
54
- const targetIdx = order.find((i) => isFree(stripped[i])) ?? order.find(noInterlude) ?? order[0] ?? n - 1;
49
+ const targetIdx = order.find((i) => isFree(stripped[i])) ??
50
+ order.find((i) => clear(i) && noCarousel(i)) ??
51
+ order.find(clear) ??
52
+ everywhere.find((i) => clear(i) && noCarousel(i)) ??
53
+ everywhere.find(clear) ??
54
+ order.find(noInterlude) ??
55
+ order[0] ??
56
+ n - 1;
55
57
  const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
56
58
  return stripped.map((section, i) => i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted, afterParagraph }] });
57
59
  }
@@ -59,6 +59,7 @@ export function createSchemaContext(input) {
59
59
  pageUrl: toAbsoluteSiteUrl(input.pagePath, siteUrl, basePath),
60
60
  orgId: `${siteBaseUrl}#organization`,
61
61
  websiteId: `${siteBaseUrl}#website`,
62
+ inLanguage: input.inLanguage || 'en',
62
63
  abs: (path) => `${siteUrl}${basePath}${path}`,
63
64
  absOrHttp: (path) => (path.startsWith('http') ? path : `${siteUrl}${basePath}${path}`),
64
65
  route: (kind, slug) => `${siteUrl}${basePath}/${routeSegment(kind, routes)}/${slug}`,
@@ -52,8 +52,9 @@ function eventNode(ctx, policy, data, parts) {
52
52
  }
53
53
  /** Event at route `event`, its author's Person first, and a companion Article (SLA-357). */
54
54
  export function eventBuilder(options) {
55
- const { offersArray = false, emitEvent = () => true, articleSection = 'Events', inLanguage = 'en', currency = 'EUR' } = options;
55
+ const { offersArray = false, emitEvent = () => true, articleSection = 'Events', inLanguage: optionInLanguage, currency = 'EUR' } = options;
56
56
  return (data, ctx) => {
57
+ const inLanguage = optionInLanguage ?? ctx.inLanguage ?? 'en';
57
58
  const { isFree, price } = eventPrice(data);
58
59
  const validFrom = offerValidFrom(data.startDate);
59
60
  const pageRoute = ctx.route('event', data.slug);
@@ -13,7 +13,7 @@ export function buildBreadcrumbList(ctx, breadcrumbs) {
13
13
  };
14
14
  }
15
15
  /** The page's WebPage node: name/description/dates fall back to the first entries that carry them. */
16
- export function buildWebPageNode(ctx, page, inLanguage = 'en') {
16
+ export function buildWebPageNode(ctx, page, inLanguage = ctx.inLanguage ?? 'en') {
17
17
  const { entries } = page;
18
18
  return {
19
19
  '@type': 'WebPage',
@@ -38,7 +38,7 @@ export function buildWebPageNode(ctx, page, inLanguage = 'en') {
38
38
  * then each entry's node(s) in call order. A type with no builder, or a builder returning null, emits nothing.
39
39
  */
40
40
  export function assembleGraph(ctx, options) {
41
- const graph = [options.organization, options.website, buildWebPageNode(ctx, options, options.inLanguage)];
41
+ const graph = [options.organization, options.website, buildWebPageNode(ctx, options, options.inLanguage ?? ctx.inLanguage)];
42
42
  if (options.breadcrumbs)
43
43
  graph.push(buildBreadcrumbList(ctx, options.breadcrumbs));
44
44
  options.beforeEntries?.(graph);
@@ -16,6 +16,7 @@ export declare function placeNode(ctx: SchemaContext, data: Record<string, any>,
16
16
  export interface SiteNodeFields {
17
17
  name: string;
18
18
  description: string;
19
+ inLanguage?: string;
19
20
  }
20
21
  export interface OrganizationLogo {
21
22
  path: string;
@@ -25,4 +26,4 @@ export interface OrganizationLogo {
25
26
  /** The base graph's Organization; `extra` (sameAs, knowsAbout, …) follows the description. */
26
27
  export declare function siteOrganizationNode(ctx: SchemaContext, { name, description }: SiteNodeFields, logo?: OrganizationLogo, extra?: JsonLdNode): JsonLdNode;
27
28
  /** The base graph's WebSite, published by the Organization; `extra` (a SearchAction, …) follows. */
28
- export declare function siteWebsiteNode(ctx: SchemaContext, { name, description }: SiteNodeFields, extra?: JsonLdNode): JsonLdNode;
29
+ export declare function siteWebsiteNode(ctx: SchemaContext, { name, description, inLanguage }: SiteNodeFields, extra?: JsonLdNode): JsonLdNode;
@@ -35,14 +35,14 @@ export function siteOrganizationNode(ctx, { name, description }, logo = { path:
35
35
  };
36
36
  }
37
37
  /** The base graph's WebSite, published by the Organization; `extra` (a SearchAction, …) follows. */
38
- export function siteWebsiteNode(ctx, { name, description }, extra = {}) {
38
+ export function siteWebsiteNode(ctx, { name, description, inLanguage }, extra = {}) {
39
39
  return {
40
40
  '@type': 'WebSite',
41
41
  '@id': ctx.websiteId,
42
42
  name,
43
43
  description,
44
44
  url: ctx.siteBaseUrl,
45
- inLanguage: 'en',
45
+ inLanguage: inLanguage ?? ctx.inLanguage ?? 'en',
46
46
  publisher: { '@id': ctx.orgId },
47
47
  ...extra,
48
48
  };
@@ -23,8 +23,9 @@ export function faqPageBuilder() {
23
23
  * The FAQPage here keeps question and answer text as given, unlike `faqPageBuilder`.
24
24
  */
25
25
  export function articleBuilder(options = {}) {
26
- const { imageVariants = false, defaultImage = '/og-default.jpg', defaultSection = 'Travel Guide', inLanguage = 'en', speakableSelectors = ['h1', '.article-lede'], } = options;
26
+ const { imageVariants = false, defaultImage = '/og-default.jpg', defaultSection = 'Travel Guide', inLanguage: optionInLanguage, speakableSelectors = ['h1', '.article-lede'], } = options;
27
27
  return (data, ctx) => {
28
+ const inLanguage = optionInLanguage ?? ctx.inLanguage ?? 'en';
28
29
  const articleImageUrl = data.image ? ctx.resolveImageUrl(data.image, data.slug) : ctx.abs(defaultImage);
29
30
  const articleUrl = data.url ? ctx.absOrHttp(data.url) : ctx.pageUrl;
30
31
  const author = ctx.resolveAuthor(data.author);
@@ -51,6 +51,8 @@ export interface SchemaContextInput {
51
51
  routes?: RouteMap;
52
52
  /** Clock for the future-date clamp and `defaultToNow`. */
53
53
  now?: () => Date;
54
+ /** BCP-47 language tag for JSON-LD `inLanguage` (defaults to `'en'`). */
55
+ inLanguage?: string;
54
56
  }
55
57
  export interface SchemaContext {
56
58
  siteUrl: string;
@@ -59,6 +61,7 @@ export interface SchemaContext {
59
61
  pageUrl: string;
60
62
  orgId: string;
61
63
  websiteId: string;
64
+ inLanguage: string;
62
65
  /** `${siteUrl}${basePath}${path}` for a root-relative path. */
63
66
  abs(path: string): string;
64
67
  /** A root-relative path made absolute; an `http…` value passes through. */
@@ -14,7 +14,7 @@
14
14
  export declare const RELATED_ZONE_ROLES: readonly ["closer"];
15
15
  export type RelatedZoneRole = (typeof RELATED_ZONE_ROLES)[number];
16
16
  /** `context` is whatever frames the page best: the entity name, its neighborhood name, or a collection noun. */
17
- export declare function closerHeading(context: string): string;
17
+ export declare function closerHeading(context: string, locale?: string): string;
18
18
  /** A guides-collection entry, as getCollection('guides') yields it. */
19
19
  type GuideEntry = {
20
20
  id: string;
@@ -14,7 +14,10 @@ import { extractProseHrefs, normalizeHref } from "./relatedDedup.js";
14
14
  /** The only heading role an entity-page tail may render. */
15
15
  export const RELATED_ZONE_ROLES = ['closer'];
16
16
  /** `context` is whatever frames the page best: the entity name, its neighborhood name, or a collection noun. */
17
- export function closerHeading(context) {
17
+ export function closerHeading(context, locale = 'en') {
18
+ if (locale === 'it' || locale.startsWith('it-')) {
19
+ return `Continua a esplorare ${context}`;
20
+ }
18
21
  return `Keep exploring ${context}`;
19
22
  }
20
23
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarimarcus/content-sites-core",
3
- "version": "0.54.0",
3
+ "version": "0.54.2",
4
4
  "description": "Non-visual utilities, Astro config builders and SEO schema assembly shared by the content sites.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -141,6 +141,7 @@ export function sitemapSerialize(
141
141
  export function defineSiteConfig(opts: SiteConfigOptions): AstroUserConfig {
142
142
  const rootDir = opts.root instanceof URL ? fileURLToPath(opts.root) : opts.root;
143
143
  const { lastmodMap, mostRecent } = buildLastmodMap(rootDir, opts.lastmod);
144
+ const lang = opts.language ?? 'en';
144
145
  return {
145
146
  ...(opts.redirects ? { redirects: opts.redirects } : {}),
146
147
  site: opts.site,
@@ -148,6 +149,10 @@ export function defineSiteConfig(opts: SiteConfigOptions): AstroUserConfig {
148
149
  output: 'static',
149
150
  trailingSlash: 'never',
150
151
  compressHTML: true,
152
+ i18n: {
153
+ defaultLocale: lang,
154
+ locales: [lang],
155
+ },
151
156
  image: {
152
157
  // Never encodes: serves the committed variants in image-variants/ (npm run images:variants writes them).
153
158
  service: {
@@ -177,7 +182,7 @@ export function defineSiteConfig(opts: SiteConfigOptions): AstroUserConfig {
177
182
  opts.pagefind({
178
183
  indexConfig: {
179
184
  excludeSelectors: [...PAGEFIND_EXCLUDE_SELECTORS],
180
- forceLanguage: opts.language ?? 'en',
185
+ forceLanguage: lang,
181
186
  },
182
187
  }),
183
188
  ],
@@ -41,12 +41,12 @@ export function formatDisplayDay(iso: string | undefined, locale: string = 'en-G
41
41
  * via `formatUtcDate`: "Aug 12" (single day), "Aug 12–13" (same month),
42
42
  * "May 29 – Jun 5" (cross-month). Returns '' when `start` is missing/invalid.
43
43
  */
44
- export function formatUtcDateRange(start?: string, end?: string): string {
45
- const s = formatUtcDate(start, { month: 'short', day: 'numeric' });
44
+ export function formatUtcDateRange(start?: string, end?: string, locale: string = 'en-US'): string {
45
+ const s = formatUtcDate(start, { month: 'short', day: 'numeric' }, locale);
46
46
  if (!s) return '';
47
47
  if (!end || end.length < 10 || end.slice(0, 10) === start!.slice(0, 10)) return s;
48
- const e = formatUtcDate(end, { month: 'short', day: 'numeric' });
48
+ const e = formatUtcDate(end, { month: 'short', day: 'numeric' }, locale);
49
49
  if (!e) return s;
50
50
  const sameMonth = start!.slice(0, 7) === end.slice(0, 7);
51
- return sameMonth ? `${s}–${formatUtcDate(end, { day: 'numeric' })}` : `${s} – ${e}`;
51
+ return sameMonth ? `${s}–${formatUtcDate(end, { day: 'numeric' }, locale)}` : `${s} – ${e}`;
52
52
  }
@@ -13,31 +13,23 @@ const occupied = (s: Section) =>
13
13
  );
14
14
  const isFree = (s: Section) => !(s.interludes?.length || s.affiliateCarousels?.length || s.inlineImages?.length);
15
15
 
16
- /**
17
- * Paragraph the feature card goes after: the section's middle, moved to the nearest slot at least two
18
- * paragraphs from any block already in the section (one paragraph of prose between), and never the last
19
- * paragraph when the section has more than one, so prose always follows the card.
20
- */
16
+ /** Slots at least two paragraphs from every block, so prose sits between; never the last paragraph of a multi-paragraph section. */
17
+ const clearSlots = (section: Section): number[] => {
18
+ const taken = occupied(section);
19
+ const last = Math.max(0, paragraphsOf(section) - 2);
20
+ return Array.from({ length: last + 1 }, (_, p) => p).filter((p) => taken.every((t) => Math.abs(t - p) >= 2));
21
+ };
22
+
23
+ /** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
21
24
  export function pickFeatureParagraph(section: Section): number {
22
25
  const count = paragraphsOf(section);
23
- const last = Math.max(0, count - 2);
24
26
  const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
25
- const taken = occupied(section);
26
- const ok = (p: number) => taken.every((t) => Math.abs(t - p) >= 2);
27
- let best = -1;
28
- for (let p = 0; p <= last; p++) {
29
- if (ok(p) && (best < 0 || Math.abs(p - preferred) < Math.abs(best - preferred))) best = p;
30
- }
31
- return best >= 0 ? best : Math.min(preferred, last);
27
+ const slots = clearSlots(section);
28
+ if (!slots.length) return Math.min(preferred, Math.max(0, count - 2));
29
+ return slots.reduce((best, p) => (Math.abs(p - preferred) < Math.abs(best - preferred) ? p : best));
32
30
  }
33
31
 
34
- /**
35
- * Moves the single `article-feature` interlude to its display slot: the last free back-half section
36
- * (or ~40% depth on a Discover piece). A section is free when it holds no interlude, affiliate carousel
37
- * or inline image; with none free it falls back to a section without an interlude, then to the last
38
- * section, and the paragraph pick keeps the card clear of the blocks there. Shared by every site's
39
- * article page and by scripts/validate-articles.mjs, so the gate sees what the reader sees.
40
- */
32
+ /** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
41
33
  export function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[] {
42
34
  let extracted: ({ type: string } & Partial<Block>) | null = null;
43
35
  const stripped = sections.map((section) => ({
@@ -55,8 +47,20 @@ export function relocateArticleFeature<S extends Section>(sections: S[], editori
55
47
  } else {
56
48
  for (let i = n - 1; i >= Math.ceil(n / 2); i--) order.push(i);
57
49
  }
50
+ const everywhere = Array.from({ length: n }, (_, i) => n - 1 - i);
51
+ const clearAt = stripped.map((section) => clearSlots(section).length > 0);
52
+ const clear = (i: number) => clearAt[i];
53
+ const noCarousel = (i: number) => !stripped[i].affiliateCarousels?.length;
58
54
  const noInterlude = (i: number) => !stripped[i].interludes.length;
59
- const targetIdx = order.find((i) => isFree(stripped[i])) ?? order.find(noInterlude) ?? order[0] ?? n - 1;
55
+ const targetIdx =
56
+ order.find((i) => isFree(stripped[i])) ??
57
+ order.find((i) => clear(i) && noCarousel(i)) ??
58
+ order.find(clear) ??
59
+ everywhere.find((i) => clear(i) && noCarousel(i)) ??
60
+ everywhere.find(clear) ??
61
+ order.find(noInterlude) ??
62
+ order[0] ??
63
+ n - 1;
60
64
  const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
61
65
  return stripped.map((section, i) =>
62
66
  i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted!, afterParagraph }] },
@@ -63,6 +63,7 @@ export function createSchemaContext(input: SchemaContextInput): SchemaContext {
63
63
  pageUrl: toAbsoluteSiteUrl(input.pagePath, siteUrl, basePath),
64
64
  orgId: `${siteBaseUrl}#organization`,
65
65
  websiteId: `${siteBaseUrl}#website`,
66
+ inLanguage: input.inLanguage || 'en',
66
67
  abs: (path) => `${siteUrl}${basePath}${path}`,
67
68
  absOrHttp: (path) => (path.startsWith('http') ? path : `${siteUrl}${basePath}${path}`),
68
69
  route: (kind, slug) => `${siteUrl}${basePath}/${routeSegment(kind, routes)}/${slug}`,
@@ -91,8 +91,9 @@ export interface EventOptions extends EventPolicy {
91
91
 
92
92
  /** Event at route `event`, its author's Person first, and a companion Article (SLA-357). */
93
93
  export function eventBuilder(options: EventOptions): SchemaBuilder {
94
- const { offersArray = false, emitEvent = () => true, articleSection = 'Events', inLanguage = 'en', currency = 'EUR' } = options;
94
+ const { offersArray = false, emitEvent = () => true, articleSection = 'Events', inLanguage: optionInLanguage, currency = 'EUR' } = options;
95
95
  return (data, ctx) => {
96
+ const inLanguage = optionInLanguage ?? ctx.inLanguage ?? 'en';
96
97
  const { isFree, price } = eventPrice(data);
97
98
  const validFrom = offerValidFrom(data.startDate);
98
99
  const pageRoute = ctx.route('event', data.slug);
@@ -30,7 +30,7 @@ export interface PageInput {
30
30
  }
31
31
 
32
32
  /** The page's WebPage node: name/description/dates fall back to the first entries that carry them. */
33
- export function buildWebPageNode(ctx: SchemaContext, page: PageInput, inLanguage = 'en'): JsonLdNode {
33
+ export function buildWebPageNode(ctx: SchemaContext, page: PageInput, inLanguage = ctx.inLanguage ?? 'en'): JsonLdNode {
34
34
  const { entries } = page;
35
35
  return {
36
36
  '@type': 'WebPage',
@@ -69,7 +69,7 @@ export interface AssembleOptions extends PageInput {
69
69
  * then each entry's node(s) in call order. A type with no builder, or a builder returning null, emits nothing.
70
70
  */
71
71
  export function assembleGraph(ctx: SchemaContext, options: AssembleOptions): JsonLdNode[] {
72
- const graph: JsonLdNode[] = [options.organization, options.website, buildWebPageNode(ctx, options, options.inLanguage)];
72
+ const graph: JsonLdNode[] = [options.organization, options.website, buildWebPageNode(ctx, options, options.inLanguage ?? ctx.inLanguage)];
73
73
  if (options.breadcrumbs) graph.push(buildBreadcrumbList(ctx, options.breadcrumbs));
74
74
  options.beforeEntries?.(graph);
75
75
  for (const { type, data } of options.entries) {
@@ -39,6 +39,7 @@ export function placeNode(
39
39
  export interface SiteNodeFields {
40
40
  name: string;
41
41
  description: string;
42
+ inLanguage?: string;
42
43
  }
43
44
 
44
45
  export interface OrganizationLogo {
@@ -70,14 +71,14 @@ export function siteOrganizationNode(
70
71
  }
71
72
 
72
73
  /** The base graph's WebSite, published by the Organization; `extra` (a SearchAction, …) follows. */
73
- export function siteWebsiteNode(ctx: SchemaContext, { name, description }: SiteNodeFields, extra: JsonLdNode = {}): JsonLdNode {
74
+ export function siteWebsiteNode(ctx: SchemaContext, { name, description, inLanguage }: SiteNodeFields, extra: JsonLdNode = {}): JsonLdNode {
74
75
  return {
75
76
  '@type': 'WebSite',
76
77
  '@id': ctx.websiteId,
77
78
  name,
78
79
  description,
79
80
  url: ctx.siteBaseUrl,
80
- inLanguage: 'en',
81
+ inLanguage: inLanguage ?? ctx.inLanguage ?? 'en',
81
82
  publisher: { '@id': ctx.orgId },
82
83
  ...extra,
83
84
  };
@@ -40,10 +40,11 @@ export function articleBuilder(options: ArticleOptions = {}): SchemaBuilder {
40
40
  imageVariants = false,
41
41
  defaultImage = '/og-default.jpg',
42
42
  defaultSection = 'Travel Guide',
43
- inLanguage = 'en',
43
+ inLanguage: optionInLanguage,
44
44
  speakableSelectors = ['h1', '.article-lede'],
45
45
  } = options;
46
46
  return (data, ctx) => {
47
+ const inLanguage = optionInLanguage ?? ctx.inLanguage ?? 'en';
47
48
  const articleImageUrl = data.image ? ctx.resolveImageUrl(data.image, data.slug) : ctx.abs(defaultImage);
48
49
  const articleUrl = data.url ? ctx.absOrHttp(data.url) : ctx.pageUrl;
49
50
  const author = ctx.resolveAuthor(data.author);
@@ -58,6 +58,8 @@ export interface SchemaContextInput {
58
58
  routes?: RouteMap;
59
59
  /** Clock for the future-date clamp and `defaultToNow`. */
60
60
  now?: () => Date;
61
+ /** BCP-47 language tag for JSON-LD `inLanguage` (defaults to `'en'`). */
62
+ inLanguage?: string;
61
63
  }
62
64
 
63
65
  export interface SchemaContext {
@@ -67,6 +69,7 @@ export interface SchemaContext {
67
69
  pageUrl: string;
68
70
  orgId: string;
69
71
  websiteId: string;
72
+ inLanguage: string;
70
73
  /** `${siteUrl}${basePath}${path}` for a root-relative path. */
71
74
  abs(path: string): string;
72
75
  /** A root-relative path made absolute; an `http…` value passes through. */
@@ -18,7 +18,10 @@ export const RELATED_ZONE_ROLES = ['closer'] as const;
18
18
  export type RelatedZoneRole = (typeof RELATED_ZONE_ROLES)[number];
19
19
 
20
20
  /** `context` is whatever frames the page best: the entity name, its neighborhood name, or a collection noun. */
21
- export function closerHeading(context: string): string {
21
+ export function closerHeading(context: string, locale: string = 'en'): string {
22
+ if (locale === 'it' || locale.startsWith('it-')) {
23
+ return `Continua a esplorare ${context}`;
24
+ }
22
25
  return `Keep exploring ${context}`;
23
26
  }
24
27