style: format docs site builder
This commit is contained in:
parent
ed698d9e48
commit
0ea394356f
@ -103,67 +103,68 @@ copyStaticAsset('social-card.png');
|
|||||||
fs.writeFileSync(path.join(outDir, '.nojekyll'), '', 'utf8');
|
fs.writeFileSync(path.join(outDir, '.nojekyll'), '', 'utf8');
|
||||||
if (cname) fs.writeFileSync(path.join(outDir, 'CNAME'), cname, 'utf8');
|
if (cname) fs.writeFileSync(path.join(outDir, 'CNAME'), cname, 'utf8');
|
||||||
validateLinks(outDir);
|
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)}`);
|
console.log(`built docs site: ${path.relative(root, outDir)}`);
|
||||||
|
|
||||||
function llmsTxt() {
|
function llmsTxt() {
|
||||||
const origin = docsOrigin();
|
const origin = docsOrigin();
|
||||||
const source = docsSourceUrl();
|
const source = docsSourceUrl();
|
||||||
const name = typeof productName !== "undefined" ? productName : path.basename(root);
|
const name = typeof productName !== 'undefined' ? productName : path.basename(root);
|
||||||
const description = typeof productDescription !== "undefined" ? productDescription : `${name} documentation index.`;
|
const description = typeof productDescription !== 'undefined' ? productDescription : `${name} documentation index.`;
|
||||||
const install = docsInstallHint();
|
const install = docsInstallHint();
|
||||||
const docPages = docsLlmsPages().map((page) => `- ${page.title}: ${pageUrl(origin, page.outRel)}`);
|
const docPages = docsLlmsPages().map((page) => `- ${page.title}: ${pageUrl(origin, page.outRel)}`);
|
||||||
const lines = [
|
const lines = [`# ${name}`, '', description, '', 'Canonical documentation:', ...docPages];
|
||||||
`# ${name}`,
|
|
||||||
"",
|
|
||||||
description,
|
|
||||||
"",
|
|
||||||
"Canonical documentation:",
|
|
||||||
...docPages,
|
|
||||||
];
|
|
||||||
if (install) {
|
if (install) {
|
||||||
lines.push("", "Install:", `- ${install}`);
|
lines.push('', 'Install:', `- ${install}`);
|
||||||
}
|
}
|
||||||
if (source) {
|
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.");
|
lines.push(
|
||||||
return `${lines.join("\n")}\n`;
|
'',
|
||||||
|
'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() {
|
function docsLlmsPages() {
|
||||||
const seen = new Set();
|
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));
|
return [...ordered, ...pages].filter((page) => page.outRel && !seen.has(page.outRel) && seen.add(page.outRel));
|
||||||
}
|
}
|
||||||
|
|
||||||
function docsOrigin() {
|
function docsOrigin() {
|
||||||
const value =
|
const value =
|
||||||
(typeof siteBase !== "undefined" && siteBase) ||
|
(typeof siteBase !== 'undefined' && siteBase) ||
|
||||||
(typeof siteUrl !== "undefined" && siteUrl) ||
|
(typeof siteUrl !== 'undefined' && siteUrl) ||
|
||||||
(typeof customDomain !== "undefined" && customDomain ? `https://${customDomain}` : "");
|
(typeof customDomain !== 'undefined' && customDomain ? `https://${customDomain}` : '');
|
||||||
return value.replace(/\/$/, "");
|
return value.replace(/\/$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function docsSourceUrl() {
|
function docsSourceUrl() {
|
||||||
if (typeof repoBase !== "undefined") return repoBase;
|
if (typeof repoBase !== 'undefined') return repoBase;
|
||||||
if (typeof repoUrl !== "undefined") return repoUrl;
|
if (typeof repoUrl !== 'undefined') return repoUrl;
|
||||||
if (typeof repoEditBase !== "undefined") return repoEditBase.replace(/\/edit\/main\/docs\/?$/, "");
|
if (typeof repoEditBase !== 'undefined') return repoEditBase.replace(/\/edit\/main\/docs\/?$/, '');
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function docsInstallHint() {
|
function docsInstallHint() {
|
||||||
if (typeof installCommand !== "undefined") return installCommand;
|
if (typeof installCommand !== 'undefined') return installCommand;
|
||||||
if (typeof installLine !== "undefined") return installLine;
|
if (typeof installLine !== 'undefined') return installLine;
|
||||||
if (typeof installCmd !== "undefined") return installCmd;
|
if (typeof installCmd !== 'undefined') return installCmd;
|
||||||
if (typeof installSnippet !== "undefined") return installSnippet;
|
if (typeof installSnippet !== 'undefined') return installSnippet;
|
||||||
if (typeof brewInstall !== "undefined") return brewInstall;
|
if (typeof brewInstall !== 'undefined') return brewInstall;
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageUrl(origin, outRel) {
|
function pageUrl(origin, outRel) {
|
||||||
const normalized = outRel === "index.html" ? "" : outRel.replace(/(?:^|\/)index\.html$/, (match) => match === "index.html" ? "" : "/");
|
const normalized =
|
||||||
if (!origin) return normalized || "index.html";
|
outRel === 'index.html'
|
||||||
|
? ''
|
||||||
|
: outRel.replace(/(?:^|\/)index\.html$/, (match) => (match === 'index.html' ? '' : '/'));
|
||||||
|
if (!origin) return normalized || 'index.html';
|
||||||
return normalized ? `${origin}/${normalized}` : `${origin}/`;
|
return normalized ? `${origin}/${normalized}` : `${origin}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user