@sarimarcus/content-sites-core 0.35.0 → 0.37.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 +8 -0
- package/dist/llms/index.d.ts +2 -0
- package/dist/llms/index.js +2 -0
- package/dist/llms/llmsTxt.d.ts +29 -0
- package/dist/llms/llmsTxt.js +32 -0
- package/package.json +5 -1
- package/src/llms/index.ts +3 -0
- package/src/llms/llmsTxt.ts +65 -0
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.37.0 (2026-10-14)
|
|
6
|
+
|
|
7
|
+
- `llms`: new export with `renderLlmsTxt(siteUrl, input)`, `llmsLine`, `trimDescription` and `llmsTxtResponse`, the llms.txt renderer darkskies kept as a local `llms.txt.ts`. Sections take an intro, links, bullets and prose, and a link can override the trim length; each site still selects its own items (SLA-3083).
|
|
8
|
+
|
|
9
|
+
## 0.36.0 (2026-10-14)
|
|
10
|
+
|
|
11
|
+
- No changes; lockstep release with ui (SLA-3084).
|
|
12
|
+
|
|
5
13
|
## 0.35.0 (2026-10-13)
|
|
6
14
|
|
|
7
15
|
- `url`: added `closerHeading`, `featuredInGuides(collectionOf, type, slug, guides, limit?)` and `buildTakenHrefs(sources, basePath)`, the related-zone helpers both tourism sites kept as copies. The type→collection map and the base path are now arguments instead of site imports (SLA-3042).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface LlmsLink {
|
|
2
|
+
title: string;
|
|
3
|
+
path: string;
|
|
4
|
+
description?: string | null;
|
|
5
|
+
/** Overrides the trim length for this line. */
|
|
6
|
+
maxDescription?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface LlmsSection {
|
|
9
|
+
heading: string;
|
|
10
|
+
intro?: string;
|
|
11
|
+
links?: LlmsLink[];
|
|
12
|
+
bullets?: string[];
|
|
13
|
+
prose?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LlmsTxtInput {
|
|
16
|
+
title: string;
|
|
17
|
+
summary: string;
|
|
18
|
+
preamble?: string;
|
|
19
|
+
sections: LlmsSection[];
|
|
20
|
+
maxDescription?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare const DEFAULT_MAX_DESCRIPTION = 160;
|
|
23
|
+
/** Cut at a word boundary and end with an ellipsis when over `max`. */
|
|
24
|
+
export declare function trimDescription(text: string, max?: number): string;
|
|
25
|
+
/** One `- [title](siteUrl+path): description` line. `siteUrl` has no trailing slash; `path` starts with `/`. */
|
|
26
|
+
export declare function llmsLine(siteUrl: string, link: LlmsLink, maxDescription?: number): string;
|
|
27
|
+
/** Render a spec-shaped llms.txt: H1, blockquote summary, then H2 sections. Empty sections are dropped. */
|
|
28
|
+
export declare function renderLlmsTxt(siteUrl: string, input: LlmsTxtInput): string;
|
|
29
|
+
export declare function llmsTxtResponse(body: string): Response;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const DEFAULT_MAX_DESCRIPTION = 160;
|
|
2
|
+
/** Cut at a word boundary and end with an ellipsis when over `max`. */
|
|
3
|
+
export function trimDescription(text, max = DEFAULT_MAX_DESCRIPTION) {
|
|
4
|
+
return text.length <= max ? text : `${text.slice(0, max - 1).replace(/\s+\S*$/, '')}…`;
|
|
5
|
+
}
|
|
6
|
+
/** One `- [title](siteUrl+path): description` line. `siteUrl` has no trailing slash; `path` starts with `/`. */
|
|
7
|
+
export function llmsLine(siteUrl, link, maxDescription = DEFAULT_MAX_DESCRIPTION) {
|
|
8
|
+
const description = link.description ? `: ${trimDescription(link.description, link.maxDescription ?? maxDescription)}` : '';
|
|
9
|
+
return `- [${link.title}](${siteUrl}${link.path})${description}`;
|
|
10
|
+
}
|
|
11
|
+
/** Render a spec-shaped llms.txt: H1, blockquote summary, then H2 sections. Empty sections are dropped. */
|
|
12
|
+
export function renderLlmsTxt(siteUrl, input) {
|
|
13
|
+
const max = input.maxDescription ?? DEFAULT_MAX_DESCRIPTION;
|
|
14
|
+
const head = [`# ${input.title}`, `> ${input.summary}`];
|
|
15
|
+
if (input.preamble)
|
|
16
|
+
head.push(input.preamble);
|
|
17
|
+
const sections = input.sections
|
|
18
|
+
.map((s) => {
|
|
19
|
+
const body = [
|
|
20
|
+
s.intro,
|
|
21
|
+
s.links?.length ? s.links.map((l) => llmsLine(siteUrl, l, max)).join('\n') : undefined,
|
|
22
|
+
s.bullets?.length ? s.bullets.join('\n') : undefined,
|
|
23
|
+
s.prose,
|
|
24
|
+
].filter((part) => Boolean(part));
|
|
25
|
+
return body.length ? `## ${s.heading}\n\n${body.join('\n\n')}` : undefined;
|
|
26
|
+
})
|
|
27
|
+
.filter((s) => Boolean(s));
|
|
28
|
+
return `${[head.join('\n\n'), ...sections].join('\n\n')}\n`;
|
|
29
|
+
}
|
|
30
|
+
export function llmsTxtResponse(body) {
|
|
31
|
+
return new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sarimarcus/content-sites-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
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",
|
|
@@ -58,6 +58,10 @@
|
|
|
58
58
|
"types": "./dist/text/index.d.ts",
|
|
59
59
|
"default": "./dist/text/index.js"
|
|
60
60
|
},
|
|
61
|
+
"./llms": {
|
|
62
|
+
"types": "./dist/llms/index.d.ts",
|
|
63
|
+
"default": "./dist/llms/index.js"
|
|
64
|
+
},
|
|
61
65
|
"./config": {
|
|
62
66
|
"types": "./dist/config/index.d.ts",
|
|
63
67
|
"default": "./dist/config/index.js"
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface LlmsLink {
|
|
2
|
+
title: string;
|
|
3
|
+
path: string;
|
|
4
|
+
description?: string | null;
|
|
5
|
+
/** Overrides the trim length for this line. */
|
|
6
|
+
maxDescription?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface LlmsSection {
|
|
10
|
+
heading: string;
|
|
11
|
+
intro?: string;
|
|
12
|
+
links?: LlmsLink[];
|
|
13
|
+
bullets?: string[];
|
|
14
|
+
prose?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LlmsTxtInput {
|
|
18
|
+
title: string;
|
|
19
|
+
summary: string;
|
|
20
|
+
preamble?: string;
|
|
21
|
+
sections: LlmsSection[];
|
|
22
|
+
maxDescription?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const DEFAULT_MAX_DESCRIPTION = 160;
|
|
26
|
+
|
|
27
|
+
/** Cut at a word boundary and end with an ellipsis when over `max`. */
|
|
28
|
+
export function trimDescription(text: string, max = DEFAULT_MAX_DESCRIPTION): string {
|
|
29
|
+
return text.length <= max ? text : `${text.slice(0, max - 1).replace(/\s+\S*$/, '')}…`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** One `- [title](siteUrl+path): description` line. `siteUrl` has no trailing slash; `path` starts with `/`. */
|
|
33
|
+
export function llmsLine(
|
|
34
|
+
siteUrl: string,
|
|
35
|
+
link: LlmsLink,
|
|
36
|
+
maxDescription = DEFAULT_MAX_DESCRIPTION,
|
|
37
|
+
): string {
|
|
38
|
+
const description = link.description ? `: ${trimDescription(link.description, link.maxDescription ?? maxDescription)}` : '';
|
|
39
|
+
return `- [${link.title}](${siteUrl}${link.path})${description}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Render a spec-shaped llms.txt: H1, blockquote summary, then H2 sections. Empty sections are dropped. */
|
|
43
|
+
export function renderLlmsTxt(siteUrl: string, input: LlmsTxtInput): string {
|
|
44
|
+
const max = input.maxDescription ?? DEFAULT_MAX_DESCRIPTION;
|
|
45
|
+
const head = [`# ${input.title}`, `> ${input.summary}`];
|
|
46
|
+
if (input.preamble) head.push(input.preamble);
|
|
47
|
+
|
|
48
|
+
const sections = input.sections
|
|
49
|
+
.map((s) => {
|
|
50
|
+
const body = [
|
|
51
|
+
s.intro,
|
|
52
|
+
s.links?.length ? s.links.map((l) => llmsLine(siteUrl, l, max)).join('\n') : undefined,
|
|
53
|
+
s.bullets?.length ? s.bullets.join('\n') : undefined,
|
|
54
|
+
s.prose,
|
|
55
|
+
].filter((part): part is string => Boolean(part));
|
|
56
|
+
return body.length ? `## ${s.heading}\n\n${body.join('\n\n')}` : undefined;
|
|
57
|
+
})
|
|
58
|
+
.filter((s): s is string => Boolean(s));
|
|
59
|
+
|
|
60
|
+
return `${[head.join('\n\n'), ...sections].join('\n\n')}\n`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function llmsTxtResponse(body: string): Response {
|
|
64
|
+
return new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
|
|
65
|
+
}
|