-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathllms.11ty.js
More file actions
60 lines (52 loc) · 1.67 KB
/
Copy pathllms.11ty.js
File metadata and controls
60 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Renders the spec-compliant llms.txt index at /llms.txt
// (see https://llmstxt.org). The full content dump lives at /llms-full.txt,
// generated by eleventy-plugin-llms-txt — see .eleventy.js.
const SECTIONS = [
{ tag: "base", heading: "Base utilities" },
{ tag: "components", heading: "Components" },
{ tag: "develop", heading: "Develop" },
{ tag: "foundation", heading: "Foundation" },
];
// Descriptions may contain inline HTML for the rendered page; strip it for
// llms.txt. Loop until stable so unclosed/nested-looking tags can't reintroduce
// the pattern (CodeQL js/incomplete-multi-character-sanitization).
function stripHtml(input) {
let previous;
let output = input;
do {
previous = output;
output = output.replace(/<[^>]+>/g, "");
} while (output !== previous);
return output;
}
function pageLink(page, siteUrl) {
const title = page.data.title;
const description = stripHtml(page.data.description || "")
.replace(/\s+/g, " ")
.trim();
const suffix = description ? `: ${description}` : "";
return `- [${title}](${siteUrl}${page.url})${suffix}`;
}
module.exports = class {
data() {
return {
permalink: "/llms.txt",
eleventyExcludeFromCollections: true,
};
}
render({ collections, site }) {
const sections = SECTIONS.map(({ tag, heading }) => {
const pages = (collections[tag] || [])
.slice()
.sort((a, b) =>
(a.data.title || "").localeCompare(b.data.title || "")
);
const lines = pages.map((p) => pageLink(p, site.url));
return `## ${heading}\n\n${lines.join("\n")}`;
});
return `# ${site.title}
> ${site.description}
${sections.join("\n\n")}
`;
}
};