[READ-ONLY] Mirror of https://github.com/flo-bit/tiny-docs. quick setup, simple, minimalistic docs for your github project flo-bit.dev/tiny-docs/
0

Configure Feed

Select the types of activity you want to include in your feed.

tiny-docs / scripts / update-config.js
2.0 kB 79 lines
1import fs from "node:fs"; 2import path from "node:path"; 3 4const CONFIG_PATH = "tdocs.config.json"; 5 6// Defaults derived from workflow env 7const derived = { 8 SITE: process.env.DERIVED_SITE, 9 BASE: process.env.DERIVED_BASE, 10 SITE_NAME: process.env.DERIVED_NAME, 11 12 GITHUB_URL: "https://github.com/" + process.env.DERIVED_REPO, 13 14 SHOW_THEME_TOGGLE: true, 15 SEARCH_ENABLED: true, 16 17 BASE_COLOR: "stone", 18 ACCENT_COLOR: "rose", 19}; 20 21function readExisting(path) { 22 if (!fs.existsSync(path)) return {}; 23 try { 24 const raw = fs.readFileSync(path, "utf8").trim() || "{}"; 25 return JSON.parse(raw); 26 } catch (e) { 27 console.warn( 28 "⚠️ Invalid JSON in tdocs.config.json; continuing with empty object.", 29 ); 30 return {}; 31 } 32} 33 34function normalize(merged) { 35 if ( 36 typeof merged.BASE === "string" && 37 merged.BASE && 38 !merged.BASE.startsWith("/") 39 ) { 40 merged.BASE = "/" + merged.BASE; 41 } 42 return merged; 43} 44 45const existing = readExisting(CONFIG_PATH); 46 47// Merge so existing values win; only fill in missing keys from derived 48const merged = normalize({ ...derived, ...existing }); 49 50fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2) + "\n"); 51console.log( 52 "✅ Wrote tdocs.config.json with keys:", 53 Object.keys(merged).join(", "), 54); 55 56console.log("\n🔍 Result:\n" + fs.readFileSync(CONFIG_PATH, "utf8")); 57 58function renameMdToMdx(dir = process.cwd()) { 59 // Read all items in the current directory 60 const items = fs.readdirSync(dir, { withFileTypes: true }); 61 62 for (const item of items) { 63 const fullPath = path.join(dir, item.name); 64 65 if (item.isDirectory()) { 66 // Recurse into subdirectories 67 renameMdToMdx(fullPath); 68 } else if (item.isFile() && path.extname(item.name) === ".md") { 69 const newName = path.basename(item.name, ".md") + ".mdx"; 70 const newPath = path.join(dir, newName); 71 72 fs.renameSync(fullPath, newPath); 73 console.log(`Renamed: ${fullPath}${newPath}`); 74 } 75 } 76} 77 78// Run the function 79renameMdToMdx();