Debian Codegraph @

www/src/pages/llms.txt.js

raw symbols SCIP
1 import { getFolder } from '../lib/content';
2
3 /**
4 * llms.txt, standardized entrypoint for LLM-aware clients.
5 * See https://llmstxt.org/ for the convention.
6 *
7 * Emits a short site blurb followed by a sectioned list of markdown-form
8 * pages. Each listed URL resolves to the `.md` endpoint served by
9 * pages/[...slug].md.js.
10 */
11
12 const SECTIONS = [
13 { collection: 'docs', heading: 'Documentation' },
14 { collection: 'reference', heading: 'Reference' },
15 { collection: 'patterns', heading: 'Patterns' },
16 { collection: 'essays', heading: 'Essays' },
17 { collection: 'interviews', heading: 'Interviews' },
18 ];
19
20 /** @type {import('astro').APIRoute} */
21 export const GET = async ({ site }) => {
22 const origin = site?.origin || 'https://htmx.org';
23 /** @type {string[]} */
24 const lines = [];
25
26 lines.push('# htmx');
27 lines.push('');
28 lines.push('> htmx gives you access to AJAX, CSS Transitions, WebSockets, and Server-Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypermedia.');
29 lines.push('');
30 lines.push(`The full documentation in a single file is available at [${origin}/docs.md](${origin}/docs.md).`);
31 lines.push('');
32
33 for (const { collection, heading } of SECTIONS) {
34 const folder = await getFolder(collection);
35 if (!folder.allFiles.length) continue;
36 lines.push(`## ${heading}`);
37 lines.push('');
38 if (collection === 'docs') {
39 const desc = folder.frontmatter?.description;
40 const url = `${origin}/docs.md`;
41 lines.push(desc ? `- [Documentation](${url}): ${desc}` : `- [Documentation](${url})`);
42 } else {
43 for (const file of folder.allFiles) {
44 if (file.frontmatter?.hidden) continue;
45 const title = file.frontmatter?.title ?? file.slug;
46 const desc = file.frontmatter?.description;
47 const url = `${origin}${file.url}.md`;
48 lines.push(desc ? `- [${title}](${url}): ${desc}` : `- [${title}](${url})`);
49 }
50 }
51 lines.push('');
52 }
53
54 return new Response(lines.join('\n'), {
55 headers: {
56 'Content-Type': 'text/plain; charset=utf-8',
57 'Cache-Control': 'public, max-age=3600',
58 },
59 });
60 };