diff --git a/.github/workflows/tiny-docs.yml b/.github/workflows/tiny-docs.yml index 0a3102d..3e54673 100644 --- a/.github/workflows/tiny-docs.yml +++ b/.github/workflows/tiny-docs.yml @@ -68,26 +68,17 @@ jobs: echo "base=$BASE" >> "$GITHUB_OUTPUT" echo "name=$NAME" >> "$GITHUB_OUTPUT" - - name: Create docs/config.json if missing - shell: bash - run: | - set -euo pipefail - mkdir -p docs - if [ ! -f docs/config.json ]; then - SITE='${{ steps.derive.outputs.site }}' - BASE='${{ steps.derive.outputs.base }}' - NAME='${{ steps.derive.outputs.name }}' - - printf '{\n "SITE": "%s",\n "BASE": "%s",\n "SITE_NAME": "%s"\n}\n' \ - "$SITE" "$BASE" "$NAME" > docs/config.json - - echo "Created docs/config.json, site=$SITE, base=$BASE, name=$NAME" - else - echo "docs/config.json already exists; leaving it unchanged." - fi + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 - echo "šŸ” File contents:" - cat docs/config.json + - name: Ensure docs/config.json has required fields (merge w/ defaults) + env: + DERIVED_SITE: ${{ steps.derive.outputs.site }} + DERIVED_BASE: ${{ steps.derive.outputs.base }} + DERIVED_NAME: ${{ steps.derive.outputs.name }} + run: node scripts/update-config.js - name: Install, build, and upload the site artifact uses: withastro/action@v3 diff --git a/scripts/update-config.js b/scripts/update-config.js new file mode 100644 index 0000000..2a00530 --- /dev/null +++ b/scripts/update-config.js @@ -0,0 +1,48 @@ +import fs from "node:fs"; + +const CONFIG_PATH = "docs/config.json"; + +// Defaults derived from workflow env +const derived = { + SITE: process.env.DERIVED_SITE, + BASE: process.env.DERIVED_BASE, + SITE_NAME: process.env.DERIVED_NAME, +}; + +function readExisting(path) { + if (!fs.existsSync(path)) return {}; + try { + const raw = fs.readFileSync(path, "utf8").trim() || "{}"; + return JSON.parse(raw); + } catch (e) { + console.warn( + "āš ļø Invalid JSON in docs/config.json; continuing with empty object.", + ); + return {}; + } +} + +function normalize(merged) { + if ( + typeof merged.BASE === "string" && + merged.BASE && + !merged.BASE.startsWith("/") + ) { + merged.BASE = "/" + merged.BASE; + } + return merged; +} + +fs.mkdirSync("docs", { recursive: true }); +const existing = readExisting(CONFIG_PATH); + +// Merge so existing values win; only fill in missing keys from derived +const merged = normalize({ ...derived, ...existing }); + +fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2) + "\n"); +console.log( + "āœ… Wrote docs/config.json with keys:", + Object.keys(merged).join(", "), +); + +console.log("\nšŸ” Result:\n" + fs.readFileSync(CONFIG_PATH, "utf8")); diff --git a/todo.md b/todo.md index b0dc2d2..d973369 100644 --- a/todo.md +++ b/todo.md @@ -4,4 +4,10 @@ - [x] remove numbers and docs/ folder from the urls - edit on github link - ally: add skip to content button -- make asides github flavored markdown compatible \ No newline at end of file +- make asides github flavored markdown compatible +- checkout tagged version of repo +- fix relative links +- add npx command to install either workflow or add docs-builder to your repo +- option to not include readme +- have readme as first doc +- option to rename readme \ No newline at end of file