File tree Expand file tree Collapse file tree 9 files changed +836
-23
lines changed
Expand file tree Collapse file tree 9 files changed +836
-23
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,38 @@ hugo server
101101npm run lint
102102```
103103
104+ #### HTTP Headers Configuration
105+
106+ The ` static/_headers ` file is automatically generated from
107+ ` static/_headers.config.ts ` . ** Do not edit ` static/_headers ` directly** - your
108+ changes will be overwritten.
109+
110+ ##### Making Changes to Headers
111+
112+ 1 . Edit ` static/_headers.config.ts ` (the source of truth with readable format
113+ and TypeScript type safety)
114+ 2 . Generate the headers file:
115+ ``` sh
116+ npm run build:headers
117+ ```
118+ 3 . Commit both files - a git pre-commit hook will automatically regenerate
119+ ` static/_headers ` when you modify ` _headers.config.ts `
120+
121+ ##### Automatic Synchronization
122+
123+ The files stay in sync automatically through:
124+
125+ - ** Pre-commit hook** - Regenerates ` _headers ` when ` _headers.config.ts ` changes
126+ - ** Build process** - ` build.sh ` regenerates before deployment
127+ - ** Manual generation** - Run ` npm run build:headers ` anytime
128+
129+ The TypeScript config format provides:
130+
131+ - Readable multi-line arrays for CSP directives
132+ - Native TypeScript type safety and IDE support
133+ - Easy-to-review diffs in pull requests
134+ - Zero dependencies for parsing
135+
104136## Writing Blog Posts
105137
106138Blog posts are written using
Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ if [[ "${BUILD_ENV:-}" == "preview" ]]; then
88 extra_args+=(" --buildFuture" )
99fi
1010
11+ # Generate _headers file from TypeScript configuration
12+ npx tsx scripts/generate-headers.ts
13+
1114hugo --gc --minify -b " $CF_PAGES_URL " " ${extra_args[@]} "
Original file line number Diff line number Diff line change @@ -24,4 +24,20 @@ function timed_run() {
2424 fi
2525}
2626
27+ # Regenerate static/_headers from _headers.config.ts if it changed
28+ if git diff --cached --name-only | grep -q " static/_headers.config.ts" ; then
29+ echo " Detected changes to static/_headers.config.ts, regenerating static/_headers..."
30+ npx tsx scripts/generate-headers.ts
31+ git add static/_headers
32+ echo " ✅ Updated static/_headers and added to commit"
33+ fi
34+
35+ # Also regenerate if the generator script itself changed
36+ if git diff --cached --name-only | grep -q " scripts/generate-headers.ts" ; then
37+ echo " Detected changes to generator script, regenerating static/_headers..."
38+ npx tsx scripts/generate-headers.ts
39+ git add static/_headers
40+ echo " ✅ Updated static/_headers and added to commit"
41+ fi
42+
2743timed_run " local/precious lint" " local/precious lint --staged"
You can’t perform that action at this time.
0 commit comments