style: format docs site builder

This commit is contained in:
Peter Steinberger 2026-05-11 03:13:09 +01:00
parent ed698d9e48
commit 0ea394356f
No known key found for this signature in database

View File

@ -103,67 +103,68 @@ copyStaticAsset('social-card.png');
fs.writeFileSync(path.join(outDir, '.nojekyll'), '', 'utf8');
if (cname) fs.writeFileSync(path.join(outDir, 'CNAME'), cname, 'utf8');
validateLinks(outDir);
fs.writeFileSync(path.join(outDir, "llms.txt"), llmsTxt(), "utf8");
fs.writeFileSync(path.join(outDir, 'llms.txt'), llmsTxt(), 'utf8');
console.log(`built docs site: ${path.relative(root, outDir)}`);
function llmsTxt() {
const origin = docsOrigin();
const source = docsSourceUrl();
const name = typeof productName !== "undefined" ? productName : path.basename(root);
const description = typeof productDescription !== "undefined" ? productDescription : `${name} documentation index.`;
const name = typeof productName !== 'undefined' ? productName : path.basename(root);
const description = typeof productDescription !== 'undefined' ? productDescription : `${name} documentation index.`;
const install = docsInstallHint();
const docPages = docsLlmsPages().map((page) => `- ${page.title}: ${pageUrl(origin, page.outRel)}`);
const lines = [
`# ${name}`,
"",
description,
"",
"Canonical documentation:",
...docPages,
];
const lines = [`# ${name}`, '', description, '', 'Canonical documentation:', ...docPages];
if (install) {
lines.push("", "Install:", `- ${install}`);
lines.push('', 'Install:', `- ${install}`);
}
if (source) {
lines.push("", `Source: ${source}`);
lines.push('', `Source: ${source}`);
}
lines.push("", "Guidance for agents:", "- Prefer the canonical documentation URLs above over README excerpts or package metadata.", "- Fetch only the pages needed for the current task; this is an index, not a full-site corpus.");
return `${lines.join("\n")}\n`;
lines.push(
'',
'Guidance for agents:',
'- Prefer the canonical documentation URLs above over README excerpts or package metadata.',
'- Fetch only the pages needed for the current task; this is an index, not a full-site corpus.'
);
return `${lines.join('\n')}\n`;
}
function docsLlmsPages() {
const seen = new Set();
const ordered = typeof orderedPages !== "undefined" ? orderedPages : [];
const ordered = typeof orderedPages !== 'undefined' ? orderedPages : [];
return [...ordered, ...pages].filter((page) => page.outRel && !seen.has(page.outRel) && seen.add(page.outRel));
}
function docsOrigin() {
const value =
(typeof siteBase !== "undefined" && siteBase) ||
(typeof siteUrl !== "undefined" && siteUrl) ||
(typeof customDomain !== "undefined" && customDomain ? `https://${customDomain}` : "");
return value.replace(/\/$/, "");
(typeof siteBase !== 'undefined' && siteBase) ||
(typeof siteUrl !== 'undefined' && siteUrl) ||
(typeof customDomain !== 'undefined' && customDomain ? `https://${customDomain}` : '');
return value.replace(/\/$/, '');
}
function docsSourceUrl() {
if (typeof repoBase !== "undefined") return repoBase;
if (typeof repoUrl !== "undefined") return repoUrl;
if (typeof repoEditBase !== "undefined") return repoEditBase.replace(/\/edit\/main\/docs\/?$/, "");
return "";
if (typeof repoBase !== 'undefined') return repoBase;
if (typeof repoUrl !== 'undefined') return repoUrl;
if (typeof repoEditBase !== 'undefined') return repoEditBase.replace(/\/edit\/main\/docs\/?$/, '');
return '';
}
function docsInstallHint() {
if (typeof installCommand !== "undefined") return installCommand;
if (typeof installLine !== "undefined") return installLine;
if (typeof installCmd !== "undefined") return installCmd;
if (typeof installSnippet !== "undefined") return installSnippet;
if (typeof brewInstall !== "undefined") return brewInstall;
return "";
if (typeof installCommand !== 'undefined') return installCommand;
if (typeof installLine !== 'undefined') return installLine;
if (typeof installCmd !== 'undefined') return installCmd;
if (typeof installSnippet !== 'undefined') return installSnippet;
if (typeof brewInstall !== 'undefined') return brewInstall;
return '';
}
function pageUrl(origin, outRel) {
const normalized = outRel === "index.html" ? "" : outRel.replace(/(?:^|\/)index\.html$/, (match) => match === "index.html" ? "" : "/");
if (!origin) return normalized || "index.html";
const normalized =
outRel === 'index.html'
? ''
: outRel.replace(/(?:^|\/)index\.html$/, (match) => (match === 'index.html' ? '' : '/'));
if (!origin) return normalized || 'index.html';
return normalized ? `${origin}/${normalized}` : `${origin}/`;
}