Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/stacks-docs/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(iconPlugin);
eleventyConfig.addPlugin(headerPlugin);
eleventyConfig.addPlugin(tipPlugin);
// Produces /llms-full.txt — a content dump for tools that want the full
// markdown of every page in one file. The spec-compliant index lives at
// /llms.txt and is rendered by llms.11ty.js.
eleventyConfig.addPlugin(llmsTxtPlugin, {
siteUrl: 'https://v2.stackoverflow.design',
outputPath: 'llms-full.txt',
collections: ['base', 'components', 'develop', 'foundation'],
additionalMetadata: ['description'],
normalizeWhitespace: true,
Expand Down
60 changes: 60 additions & 0 deletions packages/stacks-docs/llms.11ty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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")}
`;
}
};