Skip to content

Instantly share code, notes, and snippets.

@doomspork
Created July 28, 2025 14:48
Show Gist options
  • Save doomspork/820a5dbb0b0631e897fb4f48bdce4e85 to your computer and use it in GitHub Desktop.
Save doomspork/820a5dbb0b0631e897fb4f48bdce4e85 to your computer and use it in GitHub Desktop.
import fs from "fs";
import path from "path";
import type { ZudokuConfig } from "zudoku";
import yaml from "yaml";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Simple path resolution to specs directory
const specsDir = path.resolve(__dirname, "../specs/v4");
const generateData = (dir: string) => {
const files = fs.readdirSync(dir);
return files.filter((file) => file.endsWith(".yaml") || file.endsWith(".yml")).map((file) => {
const filePath = path.join(dir, file);
const data = fs.readFileSync(filePath, "utf8");
const json = yaml.parse(data);
return {
label: json.info.title,
input: filePath,
filename: file,
path: "/" + path.basename(file, path.extname(file)),
};
});
};
const specsData = generateData(specsDir);
const generateApis = (): ZudokuConfig["apis"] => {
return specsData.map((spec) => ({
type: "file",
input: spec.input,
path: spec.path,
options: {
disablePlayground: true,
disableSidecar: true,
}
}));
};
const generateNavigation = (): ZudokuConfig["navigation"] => {
const navi = specsData.map((spec) => ({
type: "link" as const,
icon: "book" as const,
label: spec.label,
to: spec.path,
}));
return [
{
type: "category",
label: "Documentation",
items: [
{
type: "category",
label: "APIs",
icon: "folder-cog",
collapsible: true,
collapsed: false,
items: navi,
},
],
},
];
};
// Define output directory and ensure it exists
const outputDir = path.resolve(__dirname, "generated");
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Generate and write apis.json
const apis = generateApis();
fs.writeFileSync(
path.join(outputDir, "apis.json"),
JSON.stringify(apis, null, 2),
"utf8"
);
// Generate and write navigation.json
const navigation = generateNavigation();
fs.writeFileSync(
path.join(outputDir, "navigation.json"),
JSON.stringify(navigation, null, 2),
"utf8"
);
import type { ZudokuConfig } from "zudoku";
import navigation from "./generated/navigation.json";
import apis from "./generated/apis.json";
const config: ZudokuConfig = {
site: {
logo: {
src: { light: "/logo-light.svg", dark: "/logo-dark.svg" },
alt: "Zudoku",
width: "130px",
}
},
redirects: [{ from: "/", to: "/another-site" }],
navigation: navigation as unknown as ZudokuConfig["navigation"],
apis: apis as unknown as ZudokuConfig["apis"],
};
export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment