···
68
68
echo "base=$BASE" >> "$GITHUB_OUTPUT"
69
69
echo "name=$NAME" >> "$GITHUB_OUTPUT"
70
70
71
71
-
- name: Create docs/config.json if missing
72
72
-
shell: bash
73
73
-
run: |
74
74
-
set -euo pipefail
75
75
-
mkdir -p docs
76
76
-
if [ ! -f docs/config.json ]; then
77
77
-
SITE='${{ steps.derive.outputs.site }}'
78
78
-
BASE='${{ steps.derive.outputs.base }}'
79
79
-
NAME='${{ steps.derive.outputs.name }}'
71
71
+
- name: Setup Node.js
72
72
+
uses: actions/setup-node@v4
73
73
+
with:
74
74
+
node-version: 20
80
75
81
81
-
printf '{\n "SITE": "%s",\n "BASE": "%s",\n "SITE_NAME": "%s"\n}\n' \
82
82
-
"$SITE" "$BASE" "$NAME" > docs/config.json
83
83
-
84
84
-
echo "Created docs/config.json, site=$SITE, base=$BASE, name=$NAME"
85
85
-
else
86
86
-
echo "docs/config.json already exists; leaving it unchanged."
87
87
-
fi
88
88
-
89
89
-
echo "🔍 File contents:"
90
90
-
cat docs/config.json
76
76
+
- name: Ensure docs/config.json has required fields (merge w/ defaults)
77
77
+
env:
78
78
+
DERIVED_SITE: ${{ steps.derive.outputs.site }}
79
79
+
DERIVED_BASE: ${{ steps.derive.outputs.base }}
80
80
+
DERIVED_NAME: ${{ steps.derive.outputs.name }}
81
81
+
run: node scripts/update-config.js
91
82
92
83
- name: Install, build, and upload the site artifact
93
84
uses: withastro/action@v3
···
1
1
+
import fs from "node:fs";
2
2
+
3
3
+
const CONFIG_PATH = "docs/config.json";
4
4
+
5
5
+
// Defaults derived from workflow env
6
6
+
const derived = {
7
7
+
SITE: process.env.DERIVED_SITE,
8
8
+
BASE: process.env.DERIVED_BASE,
9
9
+
SITE_NAME: process.env.DERIVED_NAME,
10
10
+
};
11
11
+
12
12
+
function readExisting(path) {
13
13
+
if (!fs.existsSync(path)) return {};
14
14
+
try {
15
15
+
const raw = fs.readFileSync(path, "utf8").trim() || "{}";
16
16
+
return JSON.parse(raw);
17
17
+
} catch (e) {
18
18
+
console.warn(
19
19
+
"⚠️ Invalid JSON in docs/config.json; continuing with empty object.",
20
20
+
);
21
21
+
return {};
22
22
+
}
23
23
+
}
24
24
+
25
25
+
function normalize(merged) {
26
26
+
if (
27
27
+
typeof merged.BASE === "string" &&
28
28
+
merged.BASE &&
29
29
+
!merged.BASE.startsWith("/")
30
30
+
) {
31
31
+
merged.BASE = "/" + merged.BASE;
32
32
+
}
33
33
+
return merged;
34
34
+
}
35
35
+
36
36
+
fs.mkdirSync("docs", { recursive: true });
37
37
+
const existing = readExisting(CONFIG_PATH);
38
38
+
39
39
+
// Merge so existing values win; only fill in missing keys from derived
40
40
+
const merged = normalize({ ...derived, ...existing });
41
41
+
42
42
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2) + "\n");
43
43
+
console.log(
44
44
+
"✅ Wrote docs/config.json with keys:",
45
45
+
Object.keys(merged).join(", "),
46
46
+
);
47
47
+
48
48
+
console.log("\n🔍 Result:\n" + fs.readFileSync(CONFIG_PATH, "utf8"));
···
4
4
- [x] remove numbers and docs/ folder from the urls
5
5
- edit on github link
6
6
- ally: add skip to content button
7
7
-
- make asides github flavored markdown compatible
7
7
+
- make asides github flavored markdown compatible
8
8
+
- checkout tagged version of repo
9
9
+
- fix relative links
10
10
+
- add npx command to install either workflow or add docs-builder to your repo
11
11
+
- option to not include readme
12
12
+
- have readme as first doc
13
13
+
- option to rename readme