Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 48 additions & 0 deletions packages/stacks-docs/llms.11ty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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" },
];

function pageLink(page, siteUrl) {
const title = page.data.title;
const description = (page.data.description || "")
.replace(/<[^>]+>/g, "") // descriptions may contain inline HTML for the rendered page

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
.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")}
`;
}
};