Created
July 28, 2025 14:48
-
-
Save doomspork/820a5dbb0b0631e897fb4f48bdce4e85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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