@sarimarcus/content-sites-core 0.36.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 CHANGED
@@ -2,6 +2,10 @@
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
+
5
9
  ## 0.36.0 (2026-10-14)
6
10
 
7
11
  - No changes; lockstep release with ui (SLA-3084).
@@ -0,0 +1,2 @@
1
+ export { renderLlmsTxt, llmsLine, trimDescription, llmsTxtResponse, DEFAULT_MAX_DESCRIPTION } from './llmsTxt.ts';
2
+ export type { LlmsLink, LlmsSection, LlmsTxtInput } from './llmsTxt.ts';
@@ -0,0 +1,2 @@
1
+ // Public surface of @sarimarcus/content-sites-core/llms.
2
+ export { renderLlmsTxt, llmsLine, trimDescription, llmsTxtResponse, DEFAULT_MAX_DESCRIPTION } from "./llmsTxt.js";
@@ -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.36.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,3 @@
1
+ // Public surface of @sarimarcus/content-sites-core/llms.
2
+ export { renderLlmsTxt, llmsLine, trimDescription, llmsTxtResponse, DEFAULT_MAX_DESCRIPTION } from './llmsTxt.ts';
3
+ export type { LlmsLink, LlmsSection, LlmsTxtInput } from './llmsTxt.ts';
@@ -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
+ }