@blogmcp/projections-core 0.1.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,16 @@
1
+ /**
2
+ * @blogmcp/projections-core
3
+ *
4
+ * Pure content projections derived from the article list: sitemap.xml, RSS,
5
+ * llms.txt / llms-full.txt, and per-page Markdown. No I/O, no framework — the KB
6
+ * API supplies the data (access-filtered) and serves the output.
7
+ *
8
+ * Cardinal rule (navigation-model.md §7): these derive from the ARTICLE LIST,
9
+ * never the nav menu. Breadcrumbs (the one nav-derived SEO artifact) live with
10
+ * the per-page renderer, not here.
11
+ */
12
+ export * from './types/index.js';
13
+ export * from './util/index.js';
14
+ export * from './sitemap/index.js';
15
+ export * from './rss/index.js';
16
+ export * from './llms/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @blogmcp/projections-core
3
+ *
4
+ * Pure content projections derived from the article list: sitemap.xml, RSS,
5
+ * llms.txt / llms-full.txt, and per-page Markdown. No I/O, no framework — the KB
6
+ * API supplies the data (access-filtered) and serves the output.
7
+ *
8
+ * Cardinal rule (navigation-model.md §7): these derive from the ARTICLE LIST,
9
+ * never the nav menu. Breadcrumbs (the one nav-derived SEO artifact) live with
10
+ * the per-page renderer, not here.
11
+ */
12
+ export * from './types/index.js';
13
+ export * from './util/index.js';
14
+ export * from './sitemap/index.js';
15
+ export * from './rss/index.js';
16
+ export * from './llms/index.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @blogmcp/projections-core — AEO surfaces (llms.txt / llms-full.txt / per-page .md)
3
+ *
4
+ * `llms.txt` is a curated index (H1 title + blockquote summary + per-tag sections
5
+ * of links with descriptions). `llms-full.txt` concatenates full article content.
6
+ * `articleToMarkdown` produces the per-page `.md` companion. The two-file split
7
+ * matches the de-facto standard (Mintlify/Anthropic/Cloudflare/Stripe). See
8
+ * navigation-model.md §7.
9
+ */
10
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
11
+ export interface LlmsOptions {
12
+ /** Locale for titles/descriptions/links (default: site default). */
13
+ readonly locale?: string;
14
+ /** Tag/group key for untagged articles (default: "Other"). */
15
+ readonly untaggedLabel?: string;
16
+ }
17
+ /** Curated index: title, summary, then per-primary-tag sections of article links. */
18
+ export declare function toLlmsTxt(articles: readonly ProjectionArticle[], site: SiteConfig, options?: LlmsOptions): string;
19
+ /** Full content dump: every indexable article's Markdown, concatenated. */
20
+ export declare function toLlmsFull(articles: readonly ProjectionArticle[], site: SiteConfig, options?: LlmsOptions): string;
21
+ /** Per-page `.md`: a small frontmatter block + the article body. */
22
+ export declare function articleToMarkdown(article: ProjectionArticle, site: SiteConfig, options?: LlmsOptions): string;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @blogmcp/projections-core — AEO surfaces (llms.txt / llms-full.txt / per-page .md)
3
+ *
4
+ * `llms.txt` is a curated index (H1 title + blockquote summary + per-tag sections
5
+ * of links with descriptions). `llms-full.txt` concatenates full article content.
6
+ * `articleToMarkdown` produces the per-page `.md` companion. The two-file split
7
+ * matches the de-facto standard (Mintlify/Anthropic/Cloudflare/Stripe). See
8
+ * navigation-model.md §7.
9
+ */
10
+ import { articleUrl, indexable, metaFor, primaryTag } from '../util/index.js';
11
+ /** Curated index: title, summary, then per-primary-tag sections of article links. */
12
+ export function toLlmsTxt(articles, site, options = {}) {
13
+ const locale = options.locale ?? site.defaultLocale;
14
+ const untagged = options.untaggedLabel ?? 'Other';
15
+ const groups = new Map();
16
+ for (const article of indexable(articles)) {
17
+ const key = primaryTag(article) ?? untagged;
18
+ const bucket = groups.get(key);
19
+ if (bucket)
20
+ bucket.push(article);
21
+ else
22
+ groups.set(key, [article]);
23
+ }
24
+ const lines = [`# ${site.title}`];
25
+ if (site.description)
26
+ lines.push('', `> ${site.description}`);
27
+ for (const key of [...groups.keys()].sort()) {
28
+ lines.push('', `## ${key}`, '');
29
+ const items = groups.get(key).sort((a, b) => metaFor(a, locale).title.localeCompare(metaFor(b, locale).title));
30
+ for (const article of items) {
31
+ const meta = metaFor(article, locale);
32
+ const linkLocale = article.locales[locale] ? locale : article.sourceLocale;
33
+ const url = articleUrl(site, article.slug, linkLocale);
34
+ lines.push(`- [${meta.title}](${url})${meta.description ? `: ${meta.description}` : ''}`);
35
+ }
36
+ }
37
+ return lines.join('\n') + '\n';
38
+ }
39
+ /** Full content dump: every indexable article's Markdown, concatenated. */
40
+ export function toLlmsFull(articles, site, options = {}) {
41
+ const locale = options.locale ?? site.defaultLocale;
42
+ const parts = [`# ${site.title}`];
43
+ if (site.description)
44
+ parts.push(`\n> ${site.description}`);
45
+ for (const article of indexable(articles)) {
46
+ parts.push('\n\n---\n');
47
+ parts.push(articleToMarkdown(article, site, { locale }));
48
+ }
49
+ return parts.join('\n') + '\n';
50
+ }
51
+ /** Per-page `.md`: a small frontmatter block + the article body. */
52
+ export function articleToMarkdown(article, site, options = {}) {
53
+ const locale = options.locale ?? site.defaultLocale;
54
+ const meta = metaFor(article, locale);
55
+ const linkLocale = article.locales[locale] ? locale : article.sourceLocale;
56
+ const url = articleUrl(site, article.slug, linkLocale);
57
+ const front = [
58
+ '---',
59
+ `title: ${yamlString(meta.title)}`,
60
+ ...(meta.description ? [`description: ${yamlString(meta.description)}`] : []),
61
+ `url: ${url}`,
62
+ `updated: ${article.updatedAt}`,
63
+ '---',
64
+ ].join('\n');
65
+ // Stored content is a full Markdown file: its own YAML frontmatter block plus a
66
+ // body that conventionally leads with the title H1. Strip the frontmatter so it
67
+ // doesn't collide with the block we just built, and only synthesize a title
68
+ // heading when the body doesn't already start with an H1 (avoids a duplicate).
69
+ const body = stripFrontmatter(article.content ?? '').trimStart();
70
+ const heading = startsWithH1(body) ? '' : `# ${meta.title}\n\n`;
71
+ return `${front}\n\n${heading}${body}`.trimEnd() + '\n';
72
+ }
73
+ /** Strip a leading YAML frontmatter block (`--- … ---`) if present. */
74
+ function stripFrontmatter(content) {
75
+ const match = /^\uFEFF?---[ \t]*\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(content);
76
+ return match ? content.slice(match[0].length) : content;
77
+ }
78
+ /** True when the body's first non-blank content is an ATX H1 (`# `, not `## `). */
79
+ function startsWithH1(body) {
80
+ return /^#(?:\s|$)/.test(body.trimStart());
81
+ }
82
+ /** Minimal YAML scalar quoting (handles colons/quotes safely). */
83
+ function yamlString(value) {
84
+ if (/[:#\n"']/.test(value))
85
+ return JSON.stringify(value);
86
+ return value;
87
+ }
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llms/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAS9E,qFAAqF;AACrF,MAAM,UAAU,SAAS,CAAC,QAAsC,EAAE,IAAgB,EAAE,UAAuB,EAAE;IAC3G,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC;IAElD,MAAM,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAC;IACtD,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC;QAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,G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AC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @blogmcp/projections-core — RSS 2.0
3
+ *
4
+ * The article list as a reverse-chronological feed (recent N). Optional locale
5
+ * (defaults to the site default). `noindex` articles are excluded.
6
+ */
7
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
8
+ export interface RssOptions {
9
+ /** Max items (default 20). */
10
+ readonly limit?: number;
11
+ /** Locale for titles/descriptions/links (default: site default). */
12
+ readonly locale?: string;
13
+ /** Path the feed is served at, for the atom:self link (default `/rss.xml`). */
14
+ readonly selfPath?: string;
15
+ }
16
+ export declare function toRss(articles: readonly ProjectionArticle[], site: SiteConfig, options?: RssOptions): string;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @blogmcp/projections-core — RSS 2.0
3
+ *
4
+ * The article list as a reverse-chronological feed (recent N). Optional locale
5
+ * (defaults to the site default). `noindex` articles are excluded.
6
+ */
7
+ import { articleUrl, indexable, metaFor, xmlEscape } from '../util/index.js';
8
+ export function toRss(articles, site, options = {}) {
9
+ const limit = options.limit ?? 20;
10
+ const locale = options.locale ?? site.defaultLocale;
11
+ const selfUrl = trimSlash(site.baseUrl) + (options.selfPath ?? '/rss.xml');
12
+ const items = indexable(articles)
13
+ .slice()
14
+ .sort((a, b) => date(b).localeCompare(date(a)))
15
+ .slice(0, limit)
16
+ .map((article) => {
17
+ const meta = metaFor(article, locale);
18
+ const linkLocale = article.locales[locale] ? locale : article.sourceLocale;
19
+ const link = articleUrl(site, article.slug, linkLocale);
20
+ const pubDate = new Date(date(article)).toUTCString();
21
+ return (` <item>` +
22
+ `<title>${xmlEscape(meta.title)}</title>` +
23
+ `<link>${xmlEscape(link)}</link>` +
24
+ `<guid isPermaLink="true">${xmlEscape(link)}</guid>` +
25
+ `<pubDate>${pubDate}</pubDate>` +
26
+ (meta.description ? `<description>${xmlEscape(meta.description)}</description>` : '') +
27
+ `</item>`);
28
+ });
29
+ return (`<?xml version="1.0" encoding="UTF-8"?>\n` +
30
+ `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">\n` +
31
+ `<channel>\n` +
32
+ ` <title>${xmlEscape(site.title)}</title>\n` +
33
+ ` <link>${xmlEscape(trimSlash(site.baseUrl))}</link>\n` +
34
+ ` <description>${xmlEscape(site.description ?? site.title)}</description>\n` +
35
+ ` <atom:link href="${xmlEscape(selfUrl)}" rel="self" type="application/rss+xml"/>\n` +
36
+ `${items.join('\n')}\n` +
37
+ `</channel>\n` +
38
+ `</rss>\n`);
39
+ }
40
+ function date(a) {
41
+ return a.publishedAt ?? a.updatedAt;
42
+ }
43
+ function trimSlash(s) {
44
+ return s.replace(/\/+$/, '');
45
+ }
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rss/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAW7E,MAAM,UAAU,KAAK,CAAC,QAAsC,EAAE,IAAgB,EAAE,UAAsB,EAAE;IACtG,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC;IACpD,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,UAAU,CAAC,CAAC;IAE3E,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC;SAC9B,KAAK,EAAE;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC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ACd,UAAU,CACX,CAAC;AACJ,CAAC;AAED,SAAS,IAAI,CAAC,CAAoB;IAChC,OAAO,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC;AAED,SAAS,SAAS,CAAC,CAAS;IAC1B,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @blogmcp/projections-core — sitemap.xml
3
+ *
4
+ * Article-list-driven (NOT nav). One `<url>` per (indexable article × locale),
5
+ * each carrying hreflang alternates for all of the article's locales + x-default.
6
+ * `lastmod` ← updatedAt. `changefreq`/`priority` are intentionally omitted
7
+ * (Google ignores them). Caller pre-filters to public + canonical; `noindex` is
8
+ * also guarded here. See navigation-model.md §7.
9
+ */
10
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
11
+ /** Soft cap before a sitemap index should be used (Google hard limit is 50k). */
12
+ export declare const SITEMAP_MAX_URLS = 45000;
13
+ export interface SitemapOptions {
14
+ /** Extra absolute URLs to include (e.g. tag-archive `/topics/<slug>` pages). */
15
+ readonly extraUrls?: readonly string[];
16
+ }
17
+ export declare function toSitemap(articles: readonly ProjectionArticle[], site: SiteConfig, options?: SitemapOptions): string;
18
+ /** Build a sitemap index pointing at child sitemap URLs (for >SITEMAP_MAX_URLS). */
19
+ export declare function toSitemapIndex(sitemapUrls: readonly string[], lastmod?: string): string;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @blogmcp/projections-core — sitemap.xml
3
+ *
4
+ * Article-list-driven (NOT nav). One `<url>` per (indexable article × locale),
5
+ * each carrying hreflang alternates for all of the article's locales + x-default.
6
+ * `lastmod` ← updatedAt. `changefreq`/`priority` are intentionally omitted
7
+ * (Google ignores them). Caller pre-filters to public + canonical; `noindex` is
8
+ * also guarded here. See navigation-model.md §7.
9
+ */
10
+ import { articleUrl, indexable, localesFor, xmlEscape } from '../util/index.js';
11
+ /** Soft cap before a sitemap index should be used (Google hard limit is 50k). */
12
+ export const SITEMAP_MAX_URLS = 45000;
13
+ export function toSitemap(articles, site, options = {}) {
14
+ const urls = [];
15
+ for (const article of indexable(articles)) {
16
+ const locales = localesFor(article, site);
17
+ const multi = locales.length > 1;
18
+ const alternates = multi
19
+ ? locales
20
+ .map((l) => alt(l, articleUrl(site, article.slug, l)))
21
+ .concat(alt('x-default', articleUrl(site, article.slug, site.defaultLocale)))
22
+ .join('')
23
+ : '';
24
+ for (const locale of locales) {
25
+ urls.push(` <url><loc>${xmlEscape(articleUrl(site, article.slug, locale))}</loc>` +
26
+ `<lastmod>${xmlEscape(article.updatedAt)}</lastmod>${alternates}</url>`);
27
+ }
28
+ }
29
+ for (const extra of options.extraUrls ?? []) {
30
+ urls.push(` <url><loc>${xmlEscape(extra)}</loc></url>`);
31
+ }
32
+ return (`<?xml version="1.0" encoding="UTF-8"?>\n` +
33
+ `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n` +
34
+ `${urls.join('\n')}\n` +
35
+ `</urlset>\n`);
36
+ }
37
+ /** Build a sitemap index pointing at child sitemap URLs (for >SITEMAP_MAX_URLS). */
38
+ export function toSitemapIndex(sitemapUrls, lastmod) {
39
+ const entries = sitemapUrls.map((u) => ` <sitemap><loc>${xmlEscape(u)}</loc>${lastmod ? `<lastmod>${xmlEscape(lastmod)}</lastmod>` : ''}</sitemap>`);
40
+ return (`<?xml version="1.0" encoding="UTF-8"?>\n` +
41
+ `<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n` +
42
+ `${entries.join('\n')}\n` +
43
+ `</sitemapindex>\n`);
44
+ }
45
+ function alt(hreflang, href) {
46
+ return `<xhtml:link rel="alternate" hreflang="${xmlEscape(hreflang)}" href="${xmlEscape(href)}"/>`;
47
+ }
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../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AE,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,eAAe,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,CACL,0CAA0C;QAC1C,2GAA2G;QAC3G,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACtB,aAAa,CACd,CAAC;AACJ,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,cAAc,CAAC,WAA8B,EAAE,OAAgB;IAC7E,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAC7B,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAmB,SAAS,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,YAAY,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,CACrH,CAAC;IACF,OAAO,CACL,0CAA0C;QAC1C,sEAAsE;QACtE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACzB,mBAAmB,CACpB,CAAC;AACJ,CAAC;AAED,SAAS,GAAG,CAAC,QAAgB,EAAE,IAAY;IACzC,OAAO,yCAAyC,SAAS,CAAC,QAAQ,CAAC,WAAW,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;AACrG,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @blogmcp/projections-core — types
3
+ *
4
+ * Content projections (sitemap / RSS / llms.txt / per-page Markdown) are derived
5
+ * from the ARTICLE LIST, never the nav menu (navigation-model.md §7). These types
6
+ * are the pure input contract; the KB API supplies the data + access filtering.
7
+ */
8
+ /** Per-locale article metadata. */
9
+ export interface ProjectionLocaleMeta {
10
+ readonly title: string;
11
+ readonly description?: string;
12
+ }
13
+ /** One article, as needed to build the projections. */
14
+ export interface ProjectionArticle {
15
+ readonly id: string;
16
+ /** URL slug — the filename WITHOUT its `.md`/`.mdx` extension. */
17
+ readonly slug: string;
18
+ /** ISO timestamp; drives sitemap `lastmod`. */
19
+ readonly updatedAt: string;
20
+ /** ISO timestamp; drives RSS `pubDate` (falls back to updatedAt). */
21
+ readonly publishedAt?: string;
22
+ /** Source language code; fallback locale for this article. */
23
+ readonly sourceLocale: string;
24
+ /** Exclude from sitemap / search / AI indexing. */
25
+ readonly noindex: boolean;
26
+ /** Tag slugs (used for llms.txt grouping). */
27
+ readonly tags: readonly string[];
28
+ /** Per-locale title/description. */
29
+ readonly locales: Readonly<Record<string, ProjectionLocaleMeta>>;
30
+ /** Full body Markdown — only required for llms-full.txt and per-page `.md`. */
31
+ readonly content?: string;
32
+ }
33
+ /** Site-level configuration for URL + feed generation. */
34
+ export interface SiteConfig {
35
+ /** Public base URL, e.g. `https://drhoubicka.cz` (trailing slash tolerated). */
36
+ readonly baseUrl: string;
37
+ readonly title: string;
38
+ readonly description?: string;
39
+ /** Default locale (no URL prefix), e.g. `cs`. */
40
+ readonly defaultLocale: string;
41
+ /** Enabled locale codes, e.g. `['cs','en']`. */
42
+ readonly locales: readonly string[];
43
+ /**
44
+ * Build the public *path* (no host) for an article in a locale. Default
45
+ * implements the blog's `prefix_except_default` + `/articles/` rule:
46
+ * default locale → `/articles/<slug>`
47
+ * other locale → `/<locale>/articles/<slug>`
48
+ */
49
+ readonly articlePath?: (slug: string, locale: string, defaultLocale: string) => string;
50
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @blogmcp/projections-core — types
3
+ *
4
+ * Content projections (sitemap / RSS / llms.txt / per-page Markdown) are derived
5
+ * from the ARTICLE LIST, never the nav menu (navigation-model.md §7). These types
6
+ * are the pure input contract; the KB API supplies the data + access filtering.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @blogmcp/projections-core — shared helpers (URL building, escaping, grouping).
3
+ */
4
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
5
+ /** Escape a string for safe inclusion in XML text/attributes. */
6
+ export declare function xmlEscape(value: string): string;
7
+ /** Strip a trailing `.md`/`.mdx` extension from a filename to get the slug. */
8
+ export declare function toSlug(filename: string): string;
9
+ /** Default `prefix_except_default` + `/articles/` path rule (matches the blog). */
10
+ export declare function defaultArticlePath(slug: string, locale: string, defaultLocale: string): string;
11
+ /** Absolute public URL for an article in a locale. */
12
+ export declare function articleUrl(site: SiteConfig, slug: string, locale: string): string;
13
+ /** Absolute public URL for a tag archive (`/topics/<slug>`) in a locale. */
14
+ export declare function topicUrl(site: SiteConfig, slug: string, locale: string): string;
15
+ /** Enabled locales the article actually has a translation for (preserves site order). */
16
+ export declare function localesFor(article: ProjectionArticle, site: SiteConfig): string[];
17
+ /** Best metadata for a locale, falling back to the source locale. */
18
+ export declare function metaFor(article: ProjectionArticle, locale: string): ProjectionLocaleMetaResolved;
19
+ export interface ProjectionLocaleMetaResolved {
20
+ readonly title: string;
21
+ readonly description?: string;
22
+ }
23
+ /** First tag by slug, or undefined. */
24
+ export declare function primaryTag(article: ProjectionArticle): string | undefined;
25
+ /** Indexable subset (drops `noindex`). */
26
+ export declare function indexable(articles: readonly ProjectionArticle[]): ProjectionArticle[];
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @blogmcp/projections-core — shared helpers (URL building, escaping, grouping).
3
+ */
4
+ /** Escape a string for safe inclusion in XML text/attributes. */
5
+ export function xmlEscape(value) {
6
+ return value.replace(/[&<>"']/g, (c) => c === '&' ? '&amp;' : c === '<' ? '&lt;' : c === '>' ? '&gt;' : c === '"' ? '&quot;' : '&apos;');
7
+ }
8
+ /** Strip a trailing `.md`/`.mdx` extension from a filename to get the slug. */
9
+ export function toSlug(filename) {
10
+ return filename.replace(/\.mdx?$/i, '');
11
+ }
12
+ function trimTrailingSlash(s) {
13
+ return s.replace(/\/+$/, '');
14
+ }
15
+ /** Default `prefix_except_default` + `/articles/` path rule (matches the blog). */
16
+ export function defaultArticlePath(slug, locale, defaultLocale) {
17
+ return locale === defaultLocale ? `/articles/${slug}` : `/${locale}/articles/${slug}`;
18
+ }
19
+ /** Absolute public URL for an article in a locale. */
20
+ export function articleUrl(site, slug, locale) {
21
+ const path = (site.articlePath ?? defaultArticlePath)(slug, locale, site.defaultLocale);
22
+ return trimTrailingSlash(site.baseUrl) + path;
23
+ }
24
+ /** Absolute public URL for a tag archive (`/topics/<slug>`) in a locale. */
25
+ export function topicUrl(site, slug, locale) {
26
+ const path = locale === site.defaultLocale ? `/topics/${slug}` : `/${locale}/topics/${slug}`;
27
+ return trimTrailingSlash(site.baseUrl) + path;
28
+ }
29
+ /** Enabled locales the article actually has a translation for (preserves site order). */
30
+ export function localesFor(article, site) {
31
+ const present = site.locales.filter((l) => article.locales[l]);
32
+ return present.length > 0 ? present : [article.sourceLocale];
33
+ }
34
+ /** Best metadata for a locale, falling back to the source locale. */
35
+ export function metaFor(article, locale) {
36
+ const m = article.locales[locale] ?? article.locales[article.sourceLocale];
37
+ return { title: m?.title ?? article.slug, description: m?.description };
38
+ }
39
+ /** First tag by slug, or undefined. */
40
+ export function primaryTag(article) {
41
+ return article.tags.length > 0 ? [...article.tags].sort()[0] : undefined;
42
+ }
43
+ /** Indexable subset (drops `noindex`). */
44
+ export function indexable(articles) {
45
+ return articles.filter((a) => !a.noindex);
46
+ }
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,iEAAiE;AACjE,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CACrC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,C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AAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAC/D,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,OAAO,CAAC,OAA0B,EAAE,MAAc;IAChE,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3E,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC;AAC1E,CAAC;AAOD,uCAAuC;AACvC,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,SAAS,CAAC,QAAsC;IAC9D,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@blogmcp/projections-core",
3
+ "version": "0.1.0",
4
+ "description": "Framework-agnostic content projections — sitemap.xml, RSS, llms.txt / llms-full.txt, and per-page Markdown — derived from the article list (not the nav menu). Zero framework dependencies.",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./src/index.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./types": {
18
+ "types": "./src/types/index.ts",
19
+ "import": "./dist/types/index.js"
20
+ },
21
+ "./sitemap": {
22
+ "types": "./src/sitemap/index.ts",
23
+ "import": "./dist/sitemap/index.js"
24
+ },
25
+ "./rss": {
26
+ "types": "./src/rss/index.ts",
27
+ "import": "./dist/rss/index.js"
28
+ },
29
+ "./llms": {
30
+ "types": "./src/llms/index.ts",
31
+ "import": "./dist/llms/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "src"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json",
40
+ "dev": "tsc -p tsconfig.build.json --watch",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
43
+ "typecheck": "tsc --noEmit"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.10.0",
47
+ "typescript": "^5.3.3",
48
+ "vitest": "^3.0.0"
49
+ },
50
+ "keywords": [
51
+ "sitemap",
52
+ "rss",
53
+ "llms.txt",
54
+ "seo",
55
+ "aeo",
56
+ "blog"
57
+ ],
58
+ "license": "MIT"
59
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @blogmcp/projections-core
3
+ *
4
+ * Pure content projections derived from the article list: sitemap.xml, RSS,
5
+ * llms.txt / llms-full.txt, and per-page Markdown. No I/O, no framework — the KB
6
+ * API supplies the data (access-filtered) and serves the output.
7
+ *
8
+ * Cardinal rule (navigation-model.md §7): these derive from the ARTICLE LIST,
9
+ * never the nav menu. Breadcrumbs (the one nav-derived SEO artifact) live with
10
+ * the per-page renderer, not here.
11
+ */
12
+
13
+ export * from './types/index.js';
14
+ export * from './util/index.js';
15
+ export * from './sitemap/index.js';
16
+ export * from './rss/index.js';
17
+ export * from './llms/index.js';
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @blogmcp/projections-core — AEO surfaces (llms.txt / llms-full.txt / per-page .md)
3
+ *
4
+ * `llms.txt` is a curated index (H1 title + blockquote summary + per-tag sections
5
+ * of links with descriptions). `llms-full.txt` concatenates full article content.
6
+ * `articleToMarkdown` produces the per-page `.md` companion. The two-file split
7
+ * matches the de-facto standard (Mintlify/Anthropic/Cloudflare/Stripe). See
8
+ * navigation-model.md §7.
9
+ */
10
+
11
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
12
+ import { articleUrl, indexable, metaFor, primaryTag } from '../util/index.js';
13
+
14
+ export interface LlmsOptions {
15
+ /** Locale for titles/descriptions/links (default: site default). */
16
+ readonly locale?: string;
17
+ /** Tag/group key for untagged articles (default: "Other"). */
18
+ readonly untaggedLabel?: string;
19
+ }
20
+
21
+ /** Curated index: title, summary, then per-primary-tag sections of article links. */
22
+ export function toLlmsTxt(articles: readonly ProjectionArticle[], site: SiteConfig, options: LlmsOptions = {}): string {
23
+ const locale = options.locale ?? site.defaultLocale;
24
+ const untagged = options.untaggedLabel ?? 'Other';
25
+
26
+ const groups = new Map<string, ProjectionArticle[]>();
27
+ for (const article of indexable(articles)) {
28
+ const key = primaryTag(article) ?? untagged;
29
+ const bucket = groups.get(key);
30
+ if (bucket) bucket.push(article);
31
+ else groups.set(key, [article]);
32
+ }
33
+
34
+ const lines: string[] = [`# ${site.title}`];
35
+ if (site.description) lines.push('', `> ${site.description}`);
36
+
37
+ for (const key of [...groups.keys()].sort()) {
38
+ lines.push('', `## ${key}`, '');
39
+ const items = groups.get(key)!.sort((a, b) => metaFor(a, locale).title.localeCompare(metaFor(b, locale).title));
40
+ for (const article of items) {
41
+ const meta = metaFor(article, locale);
42
+ const linkLocale = article.locales[locale] ? locale : article.sourceLocale;
43
+ const url = articleUrl(site, article.slug, linkLocale);
44
+ lines.push(`- [${meta.title}](${url})${meta.description ? `: ${meta.description}` : ''}`);
45
+ }
46
+ }
47
+
48
+ return lines.join('\n') + '\n';
49
+ }
50
+
51
+ /** Full content dump: every indexable article's Markdown, concatenated. */
52
+ export function toLlmsFull(articles: readonly ProjectionArticle[], site: SiteConfig, options: LlmsOptions = {}): string {
53
+ const locale = options.locale ?? site.defaultLocale;
54
+ const parts: string[] = [`# ${site.title}`];
55
+ if (site.description) parts.push(`\n> ${site.description}`);
56
+
57
+ for (const article of indexable(articles)) {
58
+ parts.push('\n\n---\n');
59
+ parts.push(articleToMarkdown(article, site, { locale }));
60
+ }
61
+ return parts.join('\n') + '\n';
62
+ }
63
+
64
+ /** Per-page `.md`: a small frontmatter block + the article body. */
65
+ export function articleToMarkdown(article: ProjectionArticle, site: SiteConfig, options: LlmsOptions = {}): string {
66
+ const locale = options.locale ?? site.defaultLocale;
67
+ const meta = metaFor(article, locale);
68
+ const linkLocale = article.locales[locale] ? locale : article.sourceLocale;
69
+ const url = articleUrl(site, article.slug, linkLocale);
70
+
71
+ const front = [
72
+ '---',
73
+ `title: ${yamlString(meta.title)}`,
74
+ ...(meta.description ? [`description: ${yamlString(meta.description)}`] : []),
75
+ `url: ${url}`,
76
+ `updated: ${article.updatedAt}`,
77
+ '---',
78
+ ].join('\n');
79
+
80
+ // Stored content is a full Markdown file: its own YAML frontmatter block plus a
81
+ // body that conventionally leads with the title H1. Strip the frontmatter so it
82
+ // doesn't collide with the block we just built, and only synthesize a title
83
+ // heading when the body doesn't already start with an H1 (avoids a duplicate).
84
+ const body = stripFrontmatter(article.content ?? '').trimStart();
85
+ const heading = startsWithH1(body) ? '' : `# ${meta.title}\n\n`;
86
+ return `${front}\n\n${heading}${body}`.trimEnd() + '\n';
87
+ }
88
+
89
+ /** Strip a leading YAML frontmatter block (`--- … ---`) if present. */
90
+ function stripFrontmatter(content: string): string {
91
+ const match = /^\uFEFF?---[ \t]*\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(content);
92
+ return match ? content.slice(match[0].length) : content;
93
+ }
94
+
95
+ /** True when the body's first non-blank content is an ATX H1 (`# `, not `## `). */
96
+ function startsWithH1(body: string): boolean {
97
+ return /^#(?:\s|$)/.test(body.trimStart());
98
+ }
99
+
100
+ /** Minimal YAML scalar quoting (handles colons/quotes safely). */
101
+ function yamlString(value: string): string {
102
+ if (/[:#\n"']/.test(value)) return JSON.stringify(value);
103
+ return value;
104
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @blogmcp/projections-core — RSS 2.0
3
+ *
4
+ * The article list as a reverse-chronological feed (recent N). Optional locale
5
+ * (defaults to the site default). `noindex` articles are excluded.
6
+ */
7
+
8
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
9
+ import { articleUrl, indexable, metaFor, xmlEscape } from '../util/index.js';
10
+
11
+ export interface RssOptions {
12
+ /** Max items (default 20). */
13
+ readonly limit?: number;
14
+ /** Locale for titles/descriptions/links (default: site default). */
15
+ readonly locale?: string;
16
+ /** Path the feed is served at, for the atom:self link (default `/rss.xml`). */
17
+ readonly selfPath?: string;
18
+ }
19
+
20
+ export function toRss(articles: readonly ProjectionArticle[], site: SiteConfig, options: RssOptions = {}): string {
21
+ const limit = options.limit ?? 20;
22
+ const locale = options.locale ?? site.defaultLocale;
23
+ const selfUrl = trimSlash(site.baseUrl) + (options.selfPath ?? '/rss.xml');
24
+
25
+ const items = indexable(articles)
26
+ .slice()
27
+ .sort((a, b) => date(b).localeCompare(date(a)))
28
+ .slice(0, limit)
29
+ .map((article) => {
30
+ const meta = metaFor(article, locale);
31
+ const linkLocale = article.locales[locale] ? locale : article.sourceLocale;
32
+ const link = articleUrl(site, article.slug, linkLocale);
33
+ const pubDate = new Date(date(article)).toUTCString();
34
+ return (
35
+ ` <item>` +
36
+ `<title>${xmlEscape(meta.title)}</title>` +
37
+ `<link>${xmlEscape(link)}</link>` +
38
+ `<guid isPermaLink="true">${xmlEscape(link)}</guid>` +
39
+ `<pubDate>${pubDate}</pubDate>` +
40
+ (meta.description ? `<description>${xmlEscape(meta.description)}</description>` : '') +
41
+ `</item>`
42
+ );
43
+ });
44
+
45
+ return (
46
+ `<?xml version="1.0" encoding="UTF-8"?>\n` +
47
+ `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">\n` +
48
+ `<channel>\n` +
49
+ ` <title>${xmlEscape(site.title)}</title>\n` +
50
+ ` <link>${xmlEscape(trimSlash(site.baseUrl))}</link>\n` +
51
+ ` <description>${xmlEscape(site.description ?? site.title)}</description>\n` +
52
+ ` <atom:link href="${xmlEscape(selfUrl)}" rel="self" type="application/rss+xml"/>\n` +
53
+ `${items.join('\n')}\n` +
54
+ `</channel>\n` +
55
+ `</rss>\n`
56
+ );
57
+ }
58
+
59
+ function date(a: ProjectionArticle): string {
60
+ return a.publishedAt ?? a.updatedAt;
61
+ }
62
+
63
+ function trimSlash(s: string): string {
64
+ return s.replace(/\/+$/, '');
65
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @blogmcp/projections-core — sitemap.xml
3
+ *
4
+ * Article-list-driven (NOT nav). One `<url>` per (indexable article × locale),
5
+ * each carrying hreflang alternates for all of the article's locales + x-default.
6
+ * `lastmod` ← updatedAt. `changefreq`/`priority` are intentionally omitted
7
+ * (Google ignores them). Caller pre-filters to public + canonical; `noindex` is
8
+ * also guarded here. See navigation-model.md §7.
9
+ */
10
+
11
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
12
+ import { articleUrl, indexable, localesFor, xmlEscape } from '../util/index.js';
13
+
14
+ /** Soft cap before a sitemap index should be used (Google hard limit is 50k). */
15
+ export const SITEMAP_MAX_URLS = 45000;
16
+
17
+ export interface SitemapOptions {
18
+ /** Extra absolute URLs to include (e.g. tag-archive `/topics/<slug>` pages). */
19
+ readonly extraUrls?: readonly string[];
20
+ }
21
+
22
+ export function toSitemap(
23
+ articles: readonly ProjectionArticle[],
24
+ site: SiteConfig,
25
+ options: SitemapOptions = {},
26
+ ): string {
27
+ const urls: string[] = [];
28
+ for (const article of indexable(articles)) {
29
+ const locales = localesFor(article, site);
30
+ const multi = locales.length > 1;
31
+ const alternates = multi
32
+ ? locales
33
+ .map((l) => alt(l, articleUrl(site, article.slug, l)))
34
+ .concat(alt('x-default', articleUrl(site, article.slug, site.defaultLocale)))
35
+ .join('')
36
+ : '';
37
+ for (const locale of locales) {
38
+ urls.push(
39
+ ` <url><loc>${xmlEscape(articleUrl(site, article.slug, locale))}</loc>` +
40
+ `<lastmod>${xmlEscape(article.updatedAt)}</lastmod>${alternates}</url>`,
41
+ );
42
+ }
43
+ }
44
+ for (const extra of options.extraUrls ?? []) {
45
+ urls.push(` <url><loc>${xmlEscape(extra)}</loc></url>`);
46
+ }
47
+ return (
48
+ `<?xml version="1.0" encoding="UTF-8"?>\n` +
49
+ `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n` +
50
+ `${urls.join('\n')}\n` +
51
+ `</urlset>\n`
52
+ );
53
+ }
54
+
55
+ /** Build a sitemap index pointing at child sitemap URLs (for >SITEMAP_MAX_URLS). */
56
+ export function toSitemapIndex(sitemapUrls: readonly string[], lastmod?: string): string {
57
+ const entries = sitemapUrls.map(
58
+ (u) => ` <sitemap><loc>${xmlEscape(u)}</loc>${lastmod ? `<lastmod>${xmlEscape(lastmod)}</lastmod>` : ''}</sitemap>`,
59
+ );
60
+ return (
61
+ `<?xml version="1.0" encoding="UTF-8"?>\n` +
62
+ `<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n` +
63
+ `${entries.join('\n')}\n` +
64
+ `</sitemapindex>\n`
65
+ );
66
+ }
67
+
68
+ function alt(hreflang: string, href: string): string {
69
+ return `<xhtml:link rel="alternate" hreflang="${xmlEscape(hreflang)}" href="${xmlEscape(href)}"/>`;
70
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @blogmcp/projections-core — types
3
+ *
4
+ * Content projections (sitemap / RSS / llms.txt / per-page Markdown) are derived
5
+ * from the ARTICLE LIST, never the nav menu (navigation-model.md §7). These types
6
+ * are the pure input contract; the KB API supplies the data + access filtering.
7
+ */
8
+
9
+ /** Per-locale article metadata. */
10
+ export interface ProjectionLocaleMeta {
11
+ readonly title: string;
12
+ readonly description?: string;
13
+ }
14
+
15
+ /** One article, as needed to build the projections. */
16
+ export interface ProjectionArticle {
17
+ readonly id: string;
18
+ /** URL slug — the filename WITHOUT its `.md`/`.mdx` extension. */
19
+ readonly slug: string;
20
+ /** ISO timestamp; drives sitemap `lastmod`. */
21
+ readonly updatedAt: string;
22
+ /** ISO timestamp; drives RSS `pubDate` (falls back to updatedAt). */
23
+ readonly publishedAt?: string;
24
+ /** Source language code; fallback locale for this article. */
25
+ readonly sourceLocale: string;
26
+ /** Exclude from sitemap / search / AI indexing. */
27
+ readonly noindex: boolean;
28
+ /** Tag slugs (used for llms.txt grouping). */
29
+ readonly tags: readonly string[];
30
+ /** Per-locale title/description. */
31
+ readonly locales: Readonly<Record<string, ProjectionLocaleMeta>>;
32
+ /** Full body Markdown — only required for llms-full.txt and per-page `.md`. */
33
+ readonly content?: string;
34
+ }
35
+
36
+ /** Site-level configuration for URL + feed generation. */
37
+ export interface SiteConfig {
38
+ /** Public base URL, e.g. `https://drhoubicka.cz` (trailing slash tolerated). */
39
+ readonly baseUrl: string;
40
+ readonly title: string;
41
+ readonly description?: string;
42
+ /** Default locale (no URL prefix), e.g. `cs`. */
43
+ readonly defaultLocale: string;
44
+ /** Enabled locale codes, e.g. `['cs','en']`. */
45
+ readonly locales: readonly string[];
46
+ /**
47
+ * Build the public *path* (no host) for an article in a locale. Default
48
+ * implements the blog's `prefix_except_default` + `/articles/` rule:
49
+ * default locale → `/articles/<slug>`
50
+ * other locale → `/<locale>/articles/<slug>`
51
+ */
52
+ readonly articlePath?: (slug: string, locale: string, defaultLocale: string) => string;
53
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @blogmcp/projections-core — shared helpers (URL building, escaping, grouping).
3
+ */
4
+
5
+ import type { ProjectionArticle, SiteConfig } from '../types/index.js';
6
+
7
+ /** Escape a string for safe inclusion in XML text/attributes. */
8
+ export function xmlEscape(value: string): string {
9
+ return value.replace(/[&<>"']/g, (c) =>
10
+ c === '&' ? '&amp;' : c === '<' ? '&lt;' : c === '>' ? '&gt;' : c === '"' ? '&quot;' : '&apos;',
11
+ );
12
+ }
13
+
14
+ /** Strip a trailing `.md`/`.mdx` extension from a filename to get the slug. */
15
+ export function toSlug(filename: string): string {
16
+ return filename.replace(/\.mdx?$/i, '');
17
+ }
18
+
19
+ function trimTrailingSlash(s: string): string {
20
+ return s.replace(/\/+$/, '');
21
+ }
22
+
23
+ /** Default `prefix_except_default` + `/articles/` path rule (matches the blog). */
24
+ export function defaultArticlePath(slug: string, locale: string, defaultLocale: string): string {
25
+ return locale === defaultLocale ? `/articles/${slug}` : `/${locale}/articles/${slug}`;
26
+ }
27
+
28
+ /** Absolute public URL for an article in a locale. */
29
+ export function articleUrl(site: SiteConfig, slug: string, locale: string): string {
30
+ const path = (site.articlePath ?? defaultArticlePath)(slug, locale, site.defaultLocale);
31
+ return trimTrailingSlash(site.baseUrl) + path;
32
+ }
33
+
34
+ /** Absolute public URL for a tag archive (`/topics/<slug>`) in a locale. */
35
+ export function topicUrl(site: SiteConfig, slug: string, locale: string): string {
36
+ const path = locale === site.defaultLocale ? `/topics/${slug}` : `/${locale}/topics/${slug}`;
37
+ return trimTrailingSlash(site.baseUrl) + path;
38
+ }
39
+
40
+ /** Enabled locales the article actually has a translation for (preserves site order). */
41
+ export function localesFor(article: ProjectionArticle, site: SiteConfig): string[] {
42
+ const present = site.locales.filter((l) => article.locales[l]);
43
+ return present.length > 0 ? present : [article.sourceLocale];
44
+ }
45
+
46
+ /** Best metadata for a locale, falling back to the source locale. */
47
+ export function metaFor(article: ProjectionArticle, locale: string): ProjectionLocaleMetaResolved {
48
+ const m = article.locales[locale] ?? article.locales[article.sourceLocale];
49
+ return { title: m?.title ?? article.slug, description: m?.description };
50
+ }
51
+
52
+ export interface ProjectionLocaleMetaResolved {
53
+ readonly title: string;
54
+ readonly description?: string;
55
+ }
56
+
57
+ /** First tag by slug, or undefined. */
58
+ export function primaryTag(article: ProjectionArticle): string | undefined {
59
+ return article.tags.length > 0 ? [...article.tags].sort()[0] : undefined;
60
+ }
61
+
62
+ /** Indexable subset (drops `noindex`). */
63
+ export function indexable(articles: readonly ProjectionArticle[]): ProjectionArticle[] {
64
+ return articles.filter((a) => !a.noindex);
65
+ }