42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import fs from "node:fs";
|
|||
|
|
import path from "node:path";
|
||
|
|
|
||
|
|
export interface DocMeta {
|
||
|
|
slug: string;
|
||
|
|
title: string;
|
||
|
|
description: string;
|
||
|
|
file: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const DOCS: DocMeta[] = [
|
||
|
|
{
|
||
|
|
slug: "api",
|
||
|
|
title: "API Reference",
|
||
|
|
description: "REST and WebSocket endpoints, auth, and request/response shapes.",
|
||
|
|
file: "API.md",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
slug: "config",
|
||
|
|
title: "Config Reference",
|
||
|
|
description: "Every field in triggershell.yml: server, auth, scripts, and variables.",
|
||
|
|
file: "CONFIG_REFERENCE.md",
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
export function getDocMeta(slug: string): DocMeta | undefined {
|
||
|
|
return DOCS.find((doc) => doc.slug === slug);
|
||
|
|
}
|
||
|
|
|
||
|
|
// docs/ ships at the repo root, one level up from this Next app - resolved at runtime rather
|
||
|
|
// than imported, since the compiled Route Handler module graph doesn't preserve source-relative
|
||
|
|
// paths (same reasoning as config path resolution in lib/config/load.ts).
|
||
|
|
function docsDir(): string {
|
||
|
|
return path.resolve(process.cwd(), "..", "docs");
|
||
|
|
}
|
||
|
|
|
||
|
|
export function readDocContent(doc: DocMeta): string | null {
|
||
|
|
const filePath = path.join(docsDir(), doc.file);
|
||
|
|
if (!fs.existsSync(/*turbopackIgnore: true*/ filePath)) return null;
|
||
|
|
return fs.readFileSync(/*turbopackIgnore: true*/ filePath, "utf-8");
|
||
|
|
}
|