@sarimarcus/content-sites-core 0.55.2 → 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.
- package/CHANGELOG.md +12 -0
- package/dist/articles/index.d.ts +6 -0
- package/dist/articles/index.js +3 -0
- package/dist/articles/listing.d.ts +118 -0
- package/dist/articles/listing.js +145 -0
- package/dist/articles/render.d.ts +34 -0
- package/dist/articles/render.js +65 -0
- package/dist/articles/schema.d.ts +473 -0
- package/dist/articles/schema.js +165 -0
- package/dist/interludes/index.d.ts +26 -14
- package/dist/interludes/index.js +18 -11
- package/dist/people/index.d.ts +36 -0
- package/dist/people/index.js +37 -0
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/policy.d.ts +30 -0
- package/dist/schema/policy.js +74 -0
- package/dist/url/routes.d.ts +2 -0
- package/dist/url/routes.js +2 -0
- package/package.json +1 -1
- package/src/articles/index.ts +15 -0
- package/src/articles/listing.ts +226 -0
- package/src/articles/render.ts +78 -0
- package/src/articles/schema.ts +223 -0
- package/src/interludes/index.ts +19 -11
- package/src/people/index.ts +45 -0
- package/src/schema/index.ts +2 -2
- package/src/schema/policy.ts +118 -0
- package/src/url/routes.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All packages in the platform release in lockstep; entries are per release version.
|
|
4
4
|
|
|
5
|
+
## 0.56.0 (2026-11-05)
|
|
6
|
+
|
|
7
|
+
- `articles`: add shared `articleSchemaFields`, `articleSuperRefineIssues`, `createArticleSchema`, `ArticleTagMeta`, and listing/pagination/tag helpers (`sortArticles`, `articlePagePath`, `articleTagPath`, `topicNeighbours`, `hubCategories`, `hubNavCategories`, `tagArticles`, `populatedTags`, `indexableTags`, `topTags`, `topCategoryTags`, `splitParagraphs`, `renderInlineMarkdown`, `toISO`, `mergeAnswerBoxFaqs`) (SLA-3715, SLA-3716, SLA-3720).
|
|
8
|
+
- `interludes`: allow `featureTypes.types` to be empty (`[]`) for articles-only editorial sites (SLA-3714).
|
|
9
|
+
- `people`: add `authorSchemaFields(z)` and `findAuthorByName(authors, name)` (SLA-3721).
|
|
10
|
+
- `schema`: add `editorialSchemaPolicy` and `profilePageAfterEntries` for articles-only JSON-LD graph assembly (SLA-3717).
|
|
11
|
+
- `url`: add `articleTag` (`articles/tag`) and `authors` (`authors`) to `DEFAULT_ROUTES` (SLA-3716, SLA-3721).
|
|
12
|
+
|
|
13
|
+
## 0.55.3 (2026-11-04)
|
|
14
|
+
|
|
15
|
+
- Lockstep release, no change (SLA-3327).
|
|
16
|
+
|
|
5
17
|
## 0.55.2 (2026-11-04)
|
|
6
18
|
|
|
7
19
|
- `affiliate`: `travelpayoutsWidgetSrc` accepts an optional `subId` on `WidgetOptions`, appending `<marker>.<subId>` to `shmarker` when non-blank (SLA-3334).
|
package/dist/articles/index.d.ts
CHANGED
|
@@ -4,3 +4,9 @@ export { selectRecentlyUpdated, isUpdatedAfterPublication, RECENT_UPDATE_WINDOW_
|
|
|
4
4
|
export type { ArticleDates } from './recent.ts';
|
|
5
5
|
export { ARTICLE_FORMATS, ARTICLE_SHAPE_UNION, FORMATS, FORMAT_NAMES, LEGACY_SHAPE, shapeFor, checkFormat, checkCounts, checkKeyFactCount, checkWords, countBodyWords, validateShape, articleShapeIssues, } from './formats.ts';
|
|
6
6
|
export type { ArticleFormat, ArticleMode, ArticleShape, FormatCard, Range, ShapeIssue, ShapeRanges } from './formats.ts';
|
|
7
|
+
export { articleSchemaFields, articleSuperRefineIssues, createArticleSchema, } from './schema.ts';
|
|
8
|
+
export type { ArticleSchemaOptions, ArticleTagMeta } from './schema.ts';
|
|
9
|
+
export { ARTICLES_PAGE_SIZE, MIN_HUB_ARTICLES, MIN_INDEXABLE_HUB_ARTICLES, MIN_INDEXABLE_TAG_ARTICLES, publishedInstant, sortArticles, totalArticlePages, articlesForPage, articlePagePath, articleTagPath, topicNeighbours, hubCategories, hubNavCategories, tagArticles, populatedTags, indexableTags, topTags, topCategoryTags, } from './listing.ts';
|
|
10
|
+
export type { ArticleHubCopy, ListableArticle, ListableArticleData } from './listing.ts';
|
|
11
|
+
export { splitParagraphs, renderInlineMarkdown, toISO, mergeAnswerBoxFaqs, } from './render.ts';
|
|
12
|
+
export type { AnswerBoxSectionLike } from './render.ts';
|
package/dist/articles/index.js
CHANGED
|
@@ -2,3 +2,6 @@
|
|
|
2
2
|
export { selectFeaturedArticles, FEATURED_SHELF_SIZE, FEATURED_MAX_AGE_DAYS } from "./featured.js";
|
|
3
3
|
export { selectRecentlyUpdated, isUpdatedAfterPublication, RECENT_UPDATE_WINDOW_DAYS, RECENT_UPDATE_MAX } from "./recent.js";
|
|
4
4
|
export { ARTICLE_FORMATS, ARTICLE_SHAPE_UNION, FORMATS, FORMAT_NAMES, LEGACY_SHAPE, shapeFor, checkFormat, checkCounts, checkKeyFactCount, checkWords, countBodyWords, validateShape, articleShapeIssues, } from "./formats.js";
|
|
5
|
+
export { articleSchemaFields, articleSuperRefineIssues, createArticleSchema, } from "./schema.js";
|
|
6
|
+
export { ARTICLES_PAGE_SIZE, MIN_HUB_ARTICLES, MIN_INDEXABLE_HUB_ARTICLES, MIN_INDEXABLE_TAG_ARTICLES, publishedInstant, sortArticles, totalArticlePages, articlesForPage, articlePagePath, articleTagPath, topicNeighbours, hubCategories, hubNavCategories, tagArticles, populatedTags, indexableTags, topTags, topCategoryTags, } from "./listing.js";
|
|
7
|
+
export { splitParagraphs, renderInlineMarkdown, toISO, mergeAnswerBoxFaqs, } from "./render.js";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type SiteRoutes } from '../url/routes.ts';
|
|
2
|
+
import type { ArticleTagMeta } from './schema.ts';
|
|
3
|
+
export declare const ARTICLES_PAGE_SIZE = 12;
|
|
4
|
+
/** Minimum articles in a category for `/articles/topic/<category>` to build. */
|
|
5
|
+
export declare const MIN_HUB_ARTICLES = 1;
|
|
6
|
+
/** Minimum articles for a topic hub to self-canonicalize and index (`< 4` is `noindex, follow` → `/articles`). */
|
|
7
|
+
export declare const MIN_INDEXABLE_HUB_ARTICLES = 4;
|
|
8
|
+
/** Minimum articles for a tag hub `/articles/tag/<tag>` to self-canonicalize and index. */
|
|
9
|
+
export declare const MIN_INDEXABLE_TAG_ARTICLES = 4;
|
|
10
|
+
export interface ArticleHubCopy {
|
|
11
|
+
/** Visible H1 on page 1 (page 2+ appends `— Page N`). */
|
|
12
|
+
h1: string;
|
|
13
|
+
/** `<title>` on page 1 (50–60 chars). */
|
|
14
|
+
seoTitle: string;
|
|
15
|
+
/** `<meta name="description">` on page 1 (150–160 chars). */
|
|
16
|
+
description: string;
|
|
17
|
+
/** Two-to-three sentence editorial lede rendered below the H1 on page 1 only. */
|
|
18
|
+
intro: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ListableArticleData {
|
|
21
|
+
slug: string;
|
|
22
|
+
title: string;
|
|
23
|
+
datePublished: string;
|
|
24
|
+
category?: string;
|
|
25
|
+
tags?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
export interface ListableArticle<D extends ListableArticleData = ListableArticleData> {
|
|
28
|
+
data: D;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Ordering timestamp for an article. A bare `YYYY-MM-DD` has no time-of-day, so articles shipped on the same day tie on
|
|
32
|
+
* `Date.parse`; we spread bare dates deterministically across the UTC day using `deterministicId(slug)` (1..86399s) so
|
|
33
|
+
* same-day articles get a stable, non-alphabetical order while any explicit `T…` timestamp wins accurately.
|
|
34
|
+
*/
|
|
35
|
+
export declare function publishedInstant(data: {
|
|
36
|
+
slug: string;
|
|
37
|
+
datePublished: string;
|
|
38
|
+
}): number;
|
|
39
|
+
/** Sort articles newest-first by `publishedInstant`, with `slug` as a final deterministic tiebreaker. */
|
|
40
|
+
export declare function sortArticles<T extends ListableArticle>(articles: readonly T[]): T[];
|
|
41
|
+
export declare function totalArticlePages(count: number, pageSize?: number): number;
|
|
42
|
+
export declare function articlesForPage<T>(sorted: readonly T[], page: number, pageSize?: number): T[];
|
|
43
|
+
/**
|
|
44
|
+
* Path for page `page` of `/articles` (no category) or `/articles/topic/<category>`.
|
|
45
|
+
* Page 1 is the canonical root (`/articles` or `/articles/topic/<category>`), never `/page/1`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function articlePagePath(page: number, category?: string, routes?: SiteRoutes): string;
|
|
48
|
+
/** Path for a controlled tag hub `/articles/tag/<tag>`. */
|
|
49
|
+
export declare function articleTagPath(tag: string, routes?: SiteRoutes): string;
|
|
50
|
+
/**
|
|
51
|
+
* Previous (older) and next (newer) articles in the same category, for `ArticleTopicPager`.
|
|
52
|
+
* `sorted` must be in `sortArticles` order (newest first, index 0 = newest).
|
|
53
|
+
*/
|
|
54
|
+
export declare function topicNeighbours<T extends ListableArticle>(sorted: readonly T[], currentSlug: string, category: string | undefined): {
|
|
55
|
+
prev: {
|
|
56
|
+
slug: string;
|
|
57
|
+
title: string;
|
|
58
|
+
} | null;
|
|
59
|
+
next: {
|
|
60
|
+
slug: string;
|
|
61
|
+
title: string;
|
|
62
|
+
} | null;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Categories that qualify for a built `/articles/topic/<category>` hub (`count >= minArticles`),
|
|
66
|
+
* in the declaration order of `categoryMap`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function hubCategories<C extends string>(articles: readonly ListableArticle[], categoryMap: Readonly<Record<C, string>>, minArticles?: number): {
|
|
69
|
+
category: C;
|
|
70
|
+
label: string;
|
|
71
|
+
count: number;
|
|
72
|
+
}[];
|
|
73
|
+
/**
|
|
74
|
+
* Subset of `hubCategories` that clear `MIN_INDEXABLE_HUB_ARTICLES` (`>= 4`).
|
|
75
|
+
* Used by `ArticleCategoryNav`, `ArticlesNavMenu`, and footer topic links so navigation
|
|
76
|
+
* never funnels internal PageRank to `noindex` hubs.
|
|
77
|
+
*/
|
|
78
|
+
export declare function hubNavCategories<C extends string>(articles: readonly ListableArticle[], categoryMap: Readonly<Record<C, string>>, minIndexable?: number): {
|
|
79
|
+
category: C;
|
|
80
|
+
label: string;
|
|
81
|
+
count: number;
|
|
82
|
+
}[];
|
|
83
|
+
/** Filter and sort articles carrying `tag`. */
|
|
84
|
+
export declare function tagArticles<T extends ListableArticle>(articles: readonly T[], tag: string): T[];
|
|
85
|
+
/**
|
|
86
|
+
* Tags from `tagMap` that have at least `minArticles` (default 1) in `articles`,
|
|
87
|
+
* sorted by descending article count then declaration order.
|
|
88
|
+
*/
|
|
89
|
+
export declare function populatedTags<K extends string>(articles: readonly ListableArticle[], tagMap: Readonly<Record<K, ArticleTagMeta>>, minArticles?: number): {
|
|
90
|
+
tag: K;
|
|
91
|
+
meta: ArticleTagMeta;
|
|
92
|
+
count: number;
|
|
93
|
+
}[];
|
|
94
|
+
/** Tags that clear `MIN_INDEXABLE_TAG_ARTICLES` (`>= 4`). */
|
|
95
|
+
export declare function indexableTags<K extends string>(articles: readonly ListableArticle[], tagMap: Readonly<Record<K, ArticleTagMeta>>, minIndexable?: number): {
|
|
96
|
+
tag: K;
|
|
97
|
+
meta: ArticleTagMeta;
|
|
98
|
+
count: number;
|
|
99
|
+
}[];
|
|
100
|
+
/**
|
|
101
|
+
* Top `limit` tags across the corpus for the header "Trending Topics" sub-bar.
|
|
102
|
+
* Prefers indexable tags (`>= 4` articles), falling back to populated tags (`>= 1`) on smaller corpora.
|
|
103
|
+
*/
|
|
104
|
+
export declare function topTags<K extends string>(articles: readonly ListableArticle[], tagMap: Readonly<Record<K, ArticleTagMeta>>, limit?: number, routes?: SiteRoutes): {
|
|
105
|
+
tag: K;
|
|
106
|
+
label: string;
|
|
107
|
+
href: string;
|
|
108
|
+
count: number;
|
|
109
|
+
}[];
|
|
110
|
+
/**
|
|
111
|
+
* Top `limit` sub-tags appearing on articles in `category`, for Xataka-style topic rail quick-pills.
|
|
112
|
+
*/
|
|
113
|
+
export declare function topCategoryTags<K extends string>(articles: readonly ListableArticle[], category: string, tagMap: Readonly<Record<K, ArticleTagMeta>>, limit?: number, routes?: SiteRoutes): {
|
|
114
|
+
tag: K;
|
|
115
|
+
label: string;
|
|
116
|
+
href: string;
|
|
117
|
+
count: number;
|
|
118
|
+
}[];
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Shared article listing, pagination, category-hub, and controlled-tag helpers (SLA-3716).
|
|
2
|
+
// Pure functions parameterized over article shape `{ data: { slug, title, datePublished, category?, tags? } }`
|
|
3
|
+
// so travel sites and editorial sites share one implementation.
|
|
4
|
+
import { routePath } from "../url/routes.js";
|
|
5
|
+
export const ARTICLES_PAGE_SIZE = 12;
|
|
6
|
+
/** Minimum articles in a category for `/articles/topic/<category>` to build. */
|
|
7
|
+
export const MIN_HUB_ARTICLES = 1;
|
|
8
|
+
/** Minimum articles for a topic hub to self-canonicalize and index (`< 4` is `noindex, follow` → `/articles`). */
|
|
9
|
+
export const MIN_INDEXABLE_HUB_ARTICLES = 4;
|
|
10
|
+
/** Minimum articles for a tag hub `/articles/tag/<tag>` to self-canonicalize and index. */
|
|
11
|
+
export const MIN_INDEXABLE_TAG_ARTICLES = 4;
|
|
12
|
+
/**
|
|
13
|
+
* Ordering timestamp for an article. A bare `YYYY-MM-DD` has no time-of-day, so articles shipped on the same day tie on
|
|
14
|
+
* `Date.parse`; we spread bare dates deterministically across the UTC day using `deterministicId(slug)` (1..86399s) so
|
|
15
|
+
* same-day articles get a stable, non-alphabetical order while any explicit `T…` timestamp wins accurately.
|
|
16
|
+
*/
|
|
17
|
+
export function publishedInstant(data) {
|
|
18
|
+
const raw = data.datePublished;
|
|
19
|
+
const base = Date.parse(raw);
|
|
20
|
+
if (raw.includes('T'))
|
|
21
|
+
return base;
|
|
22
|
+
let h = 5381;
|
|
23
|
+
for (let i = 0; i < data.slug.length; i++)
|
|
24
|
+
h = ((h * 33) ^ data.slug.charCodeAt(i)) >>> 0;
|
|
25
|
+
return base + ((h % 86399) + 1) * 1000;
|
|
26
|
+
}
|
|
27
|
+
/** Sort articles newest-first by `publishedInstant`, with `slug` as a final deterministic tiebreaker. */
|
|
28
|
+
export function sortArticles(articles) {
|
|
29
|
+
return [...articles].sort((a, b) => publishedInstant(b.data) - publishedInstant(a.data) ||
|
|
30
|
+
a.data.slug.localeCompare(b.data.slug));
|
|
31
|
+
}
|
|
32
|
+
export function totalArticlePages(count, pageSize = ARTICLES_PAGE_SIZE) {
|
|
33
|
+
return Math.max(1, Math.ceil(count / pageSize));
|
|
34
|
+
}
|
|
35
|
+
export function articlesForPage(sorted, page, pageSize = ARTICLES_PAGE_SIZE) {
|
|
36
|
+
const start = (page - 1) * pageSize;
|
|
37
|
+
return sorted.slice(start, start + pageSize);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Path for page `page` of `/articles` (no category) or `/articles/topic/<category>`.
|
|
41
|
+
* Page 1 is the canonical root (`/articles` or `/articles/topic/<category>`), never `/page/1`.
|
|
42
|
+
*/
|
|
43
|
+
export function articlePagePath(page, category, routes = {}) {
|
|
44
|
+
const root = category
|
|
45
|
+
? routePath('articleTopic', category, routes)
|
|
46
|
+
: routePath('articles', undefined, routes);
|
|
47
|
+
return page <= 1 ? root : `${root}/page/${page}`;
|
|
48
|
+
}
|
|
49
|
+
/** Path for a controlled tag hub `/articles/tag/<tag>`. */
|
|
50
|
+
export function articleTagPath(tag, routes = {}) {
|
|
51
|
+
return routePath('articleTag', tag, routes);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Previous (older) and next (newer) articles in the same category, for `ArticleTopicPager`.
|
|
55
|
+
* `sorted` must be in `sortArticles` order (newest first, index 0 = newest).
|
|
56
|
+
*/
|
|
57
|
+
export function topicNeighbours(sorted, currentSlug, category) {
|
|
58
|
+
if (!category)
|
|
59
|
+
return { prev: null, next: null };
|
|
60
|
+
const inCat = sorted.filter((a) => a.data.category === category);
|
|
61
|
+
const idx = inCat.findIndex((a) => a.data.slug === currentSlug);
|
|
62
|
+
if (idx === -1)
|
|
63
|
+
return { prev: null, next: null };
|
|
64
|
+
const newer = idx > 0 ? inCat[idx - 1] : null;
|
|
65
|
+
const older = idx < inCat.length - 1 ? inCat[idx + 1] : null;
|
|
66
|
+
return {
|
|
67
|
+
prev: older ? { slug: older.data.slug, title: older.data.title } : null,
|
|
68
|
+
next: newer ? { slug: newer.data.slug, title: newer.data.title } : null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Categories that qualify for a built `/articles/topic/<category>` hub (`count >= minArticles`),
|
|
73
|
+
* in the declaration order of `categoryMap`.
|
|
74
|
+
*/
|
|
75
|
+
export function hubCategories(articles, categoryMap, minArticles = MIN_HUB_ARTICLES) {
|
|
76
|
+
const counts = new Map();
|
|
77
|
+
for (const a of articles) {
|
|
78
|
+
const cat = a.data.category;
|
|
79
|
+
if (cat)
|
|
80
|
+
counts.set(cat, (counts.get(cat) ?? 0) + 1);
|
|
81
|
+
}
|
|
82
|
+
return Object.entries(categoryMap)
|
|
83
|
+
.map(([category, label]) => ({ category, label, count: counts.get(category) ?? 0 }))
|
|
84
|
+
.filter((entry) => entry.count >= minArticles);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Subset of `hubCategories` that clear `MIN_INDEXABLE_HUB_ARTICLES` (`>= 4`).
|
|
88
|
+
* Used by `ArticleCategoryNav`, `ArticlesNavMenu`, and footer topic links so navigation
|
|
89
|
+
* never funnels internal PageRank to `noindex` hubs.
|
|
90
|
+
*/
|
|
91
|
+
export function hubNavCategories(articles, categoryMap, minIndexable = MIN_INDEXABLE_HUB_ARTICLES) {
|
|
92
|
+
return hubCategories(articles, categoryMap, minIndexable);
|
|
93
|
+
}
|
|
94
|
+
/** Filter and sort articles carrying `tag`. */
|
|
95
|
+
export function tagArticles(articles, tag) {
|
|
96
|
+
return sortArticles(articles.filter((a) => a.data.tags?.includes(tag)));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Tags from `tagMap` that have at least `minArticles` (default 1) in `articles`,
|
|
100
|
+
* sorted by descending article count then declaration order.
|
|
101
|
+
*/
|
|
102
|
+
export function populatedTags(articles, tagMap, minArticles = 1) {
|
|
103
|
+
const counts = new Map();
|
|
104
|
+
for (const a of articles) {
|
|
105
|
+
for (const t of a.data.tags ?? []) {
|
|
106
|
+
counts.set(t, (counts.get(t) ?? 0) + 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return Object.entries(tagMap)
|
|
110
|
+
.map(([tag, meta]) => ({ tag, meta, count: counts.get(tag) ?? 0 }))
|
|
111
|
+
.filter((entry) => entry.count >= minArticles)
|
|
112
|
+
.sort((a, b) => b.count - a.count);
|
|
113
|
+
}
|
|
114
|
+
/** Tags that clear `MIN_INDEXABLE_TAG_ARTICLES` (`>= 4`). */
|
|
115
|
+
export function indexableTags(articles, tagMap, minIndexable = MIN_INDEXABLE_TAG_ARTICLES) {
|
|
116
|
+
return populatedTags(articles, tagMap, minIndexable);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Top `limit` tags across the corpus for the header "Trending Topics" sub-bar.
|
|
120
|
+
* Prefers indexable tags (`>= 4` articles), falling back to populated tags (`>= 1`) on smaller corpora.
|
|
121
|
+
*/
|
|
122
|
+
export function topTags(articles, tagMap, limit = 6, routes = {}) {
|
|
123
|
+
const indexable = indexableTags(articles, tagMap);
|
|
124
|
+
const pool = indexable.length >= Math.min(3, limit) ? indexable : populatedTags(articles, tagMap, 1);
|
|
125
|
+
return pool.slice(0, limit).map(({ tag, meta, count }) => ({
|
|
126
|
+
tag,
|
|
127
|
+
label: meta.label,
|
|
128
|
+
href: articleTagPath(tag, routes),
|
|
129
|
+
count,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Top `limit` sub-tags appearing on articles in `category`, for Xataka-style topic rail quick-pills.
|
|
134
|
+
*/
|
|
135
|
+
export function topCategoryTags(articles, category, tagMap, limit = 4, routes = {}) {
|
|
136
|
+
const inCat = articles.filter((a) => a.data.category === category);
|
|
137
|
+
return populatedTags(inCat, tagMap, 1)
|
|
138
|
+
.slice(0, limit)
|
|
139
|
+
.map(({ tag, meta, count }) => ({
|
|
140
|
+
tag,
|
|
141
|
+
label: meta.label,
|
|
142
|
+
href: articleTagPath(tag, routes),
|
|
143
|
+
count,
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a markdown body on blank lines (`\n\n+`) and renders each chunk:
|
|
3
|
+
* block-level markdown constructs (lists, blockquotes, tables) use `parseMarkdownBlock`
|
|
4
|
+
* while ordinary prose paragraphs are wrapped in `<p>` via `parseMarkdownInline`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function splitParagraphs(body: string, basePath?: string, sourcesLength?: number): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Inline markdown to HTML with footnote conversion (`[^N]` → `<sup><a href="#fn-N">[N]</a></sup>`),
|
|
9
|
+
* used by `Interlude.astro` and `ArticleKeyFacts.astro`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderInlineMarkdown(text: string, basePath?: string, sourcesLength?: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Normalizes a `YYYY-MM-DD` date string (or ISO string) into a full ISO-8601 timestamp with timezone offset
|
|
14
|
+
* in `timeZone` (defaults to `'Europe/Madrid'`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function toISO(dateStr: string | undefined, timeZone?: string): string | undefined;
|
|
17
|
+
export interface AnswerBoxSectionLike {
|
|
18
|
+
interludes?: readonly {
|
|
19
|
+
type: string;
|
|
20
|
+
question?: string;
|
|
21
|
+
answer?: string;
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Merges `answer-box` interludes from `sections` into the article's `faqs` list (deduping by lowercase question)
|
|
26
|
+
* so `StructuredData.astro` emits a complete `FAQPage` node matching the visible Q&As on the page.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mergeAnswerBoxFaqs(faqs: readonly {
|
|
29
|
+
question: string;
|
|
30
|
+
answer: string;
|
|
31
|
+
}[] | undefined, sections: readonly AnswerBoxSectionLike[] | undefined): {
|
|
32
|
+
question: string;
|
|
33
|
+
answer: string;
|
|
34
|
+
}[];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Shared article prose and metadata helpers promoted from the sites' src/utils/articleRender.ts (SLA-3720).
|
|
2
|
+
import { parseMarkdownBlock, parseMarkdownInline } from "../text/markdown.js";
|
|
3
|
+
/**
|
|
4
|
+
* Splits a markdown body on blank lines (`\n\n+`) and renders each chunk:
|
|
5
|
+
* block-level markdown constructs (lists, blockquotes, tables) use `parseMarkdownBlock`
|
|
6
|
+
* while ordinary prose paragraphs are wrapped in `<p>` via `parseMarkdownInline`.
|
|
7
|
+
*/
|
|
8
|
+
export function splitParagraphs(body, basePath = '/', sourcesLength) {
|
|
9
|
+
return body
|
|
10
|
+
.split(/\n\n+/)
|
|
11
|
+
.map((p) => p.trim())
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.map((chunk) => {
|
|
14
|
+
if (/^(?:[-*+]|\d+\.)\s|^>\s|^\|/m.test(chunk)) {
|
|
15
|
+
return parseMarkdownBlock(chunk, basePath, sourcesLength);
|
|
16
|
+
}
|
|
17
|
+
return `<p>${parseMarkdownInline(chunk, basePath, sourcesLength)}</p>`;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Inline markdown to HTML with footnote conversion (`[^N]` → `<sup><a href="#fn-N">[N]</a></sup>`),
|
|
22
|
+
* used by `Interlude.astro` and `ArticleKeyFacts.astro`.
|
|
23
|
+
*/
|
|
24
|
+
export function renderInlineMarkdown(text, basePath = '/', sourcesLength) {
|
|
25
|
+
return parseMarkdownInline(text, basePath, sourcesLength);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes a `YYYY-MM-DD` date string (or ISO string) into a full ISO-8601 timestamp with timezone offset
|
|
29
|
+
* in `timeZone` (defaults to `'Europe/Madrid'`).
|
|
30
|
+
*/
|
|
31
|
+
export function toISO(dateStr, timeZone = 'Europe/Madrid') {
|
|
32
|
+
if (!dateStr)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (dateStr.includes('T'))
|
|
35
|
+
return dateStr;
|
|
36
|
+
const probe = new Date(`${dateStr}T12:00:00Z`);
|
|
37
|
+
const tzPart = new Intl.DateTimeFormat('en-US', {
|
|
38
|
+
timeZone,
|
|
39
|
+
timeZoneName: 'longOffset',
|
|
40
|
+
})
|
|
41
|
+
.formatToParts(probe)
|
|
42
|
+
.find((p) => p.type === 'timeZoneName')?.value;
|
|
43
|
+
const offset = tzPart?.replace(/^GMT/, '') || '+01:00';
|
|
44
|
+
return `${dateStr}T00:00:00${offset}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Merges `answer-box` interludes from `sections` into the article's `faqs` list (deduping by lowercase question)
|
|
48
|
+
* so `StructuredData.astro` emits a complete `FAQPage` node matching the visible Q&As on the page.
|
|
49
|
+
*/
|
|
50
|
+
export function mergeAnswerBoxFaqs(faqs, sections) {
|
|
51
|
+
const base = [...(faqs ?? [])];
|
|
52
|
+
const seen = new Set(base.map((f) => f.question.trim().toLowerCase()));
|
|
53
|
+
for (const s of sections ?? []) {
|
|
54
|
+
for (const item of s.interludes ?? []) {
|
|
55
|
+
if (item.type === 'answer-box' && item.question && item.answer) {
|
|
56
|
+
const key = item.question.trim().toLowerCase();
|
|
57
|
+
if (!seen.has(key)) {
|
|
58
|
+
seen.add(key);
|
|
59
|
+
base.push({ question: item.question, answer: item.answer });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return base;
|
|
65
|
+
}
|