-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs_post.ps1
More file actions
81 lines (62 loc) · 2.26 KB
/
docs_post.ps1
File metadata and controls
81 lines (62 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<#
.SCRIPTNAME
post_docs.ps1
.SYNOPSIS
Post-processing script for Civic Dev Zig-generated docs.
- Adjusts paths for local + GitHub Pages use.
- Removes problematic styles.
- Ensures sources.tar loads from relative path.
#>
Write-Host "Running post_docs.ps1 ..."
$indexPath = Join-Path -Path "." -ChildPath "docs\index.html"
$mainJsPath = Join-Path -Path "." -ChildPath "docs\main.js"
# --- Patch docs/index.html ---
if (Test-Path $indexPath) {
Write-Host "Patching $indexPath ..."
$content = Get-Content $indexPath -Raw
# Change <script src="main.js"> to ./main.js
$content = $content -replace '<script src="main\.js">', '<script src="./main.js">'
# Remove box-shadow-color style rule entirely
$content = $content -replace 'box-shadow-color:[^;"]*;', ''
# Change box-shadow rule:
# box-shadow: inset 0 -1px 0;
# → box-shadow: inset 0 -1px 0 #c6cbd1;
$content = $content -replace 'box-shadow:\s*inset 0 -1px 0;', 'box-shadow: inset 0 -1px 0 #c6cbd1;'
# Add dynamic <base> tag logic at top of body
if ($content -notmatch 'Running in local mode') {
$baseScript = @"
<script>
(function () {
const isGhPages = location.hostname.endsWith('.github.io');
if (isGhPages) {
const repo = '/civic-dev/docs/';
const base = document.createElement('base');
base.href = repo;
document.head.appendChild(base);
}
else {
console.log('Running in local mode — no <base> tag needed.');
}
})();
</script>
"@
# Insert right after opening <body>
$content = $content -replace '(<body[^>]*>)', "`$1`n$baseScript"
}
Set-Content -Path $indexPath -Value $content -Encoding UTF8
Write-Host "Updated $indexPath"
} else {
Write-Warning "$indexPath not found"
}
# --- Patch docs/main.js ---
if (Test-Path $mainJsPath) {
Write-Host "Patching $mainJsPath ..."
$content = Get-Content $mainJsPath -Raw
# Replace fetch("sources.tar") → fetch("./sources.tar")
$content = $content -replace 'fetch\("sources\.tar"\)', 'fetch("./sources.tar")'
Set-Content -Path $mainJsPath -Value $content -Encoding UTF8
Write-Host "Updated $mainJsPath"
} else {
Write-Warning "$mainJsPath not found"
}
Write-Host "post_docs.ps1 finished."