SPB Git

Repository Public MIT

content.ts 1.5 KB 40 lines typescript

1import "server-only";2import { existsSync, readdirSync, readFileSync } from "node:fs";3import { join } from "node:path";4import { splitFrontmatter } from "@skills/registry-core";5import { parse } from "yaml";67/** First-party Markdown content (docs, legal, about). Trusted: it ships with the application. */8const ROOT = join(process.cwd(), "content");910export interface Doc {11  slug: string;12  title: string;13  description: string;14  order: number;15  section: string;16  body: string;17}1819function read(dir: string, file: string): Doc | null {20  const p = join(ROOT, dir, file);21  if (!existsSync(p)) return null;22  const { frontmatter, body } = splitFrontmatter(readFileSync(p, "utf8"));23  const fm = (frontmatter ? parse(frontmatter) : {}) as Partial<Doc>;24  const slug = file.replace(/\.md$/, "");25  return { slug, title: fm.title ?? slug, description: fm.description ?? "", order: Number(fm.order ?? 99), section: fm.section ?? "Reference", body };26}2728export function listDocs(): Doc[] {29  const dir = join(ROOT, "docs");30  if (!existsSync(dir)) return [];31  return readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => read("docs", f)!).sort((a, b) => a.order - b.order || a.title.localeCompare(b.title));32}33export function getDoc(slug: string): Doc | null {34  return /^[a-z0-9-]{1,64}$/.test(slug) ? read("docs", `${slug}.md`) : null;35}36export function getPage(dir: "legal" | ".", slug: string): Doc | null {37  return /^[a-z0-9-]{1,64}$/.test(slug) ? read(dir, `${slug}.md`) : null;38}39export const DOC_SECTIONS = ["Start", "Install", "Publish", "Reference", "Trust"];40
Files main
Menu

Theme