-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalizeAssetPaths.ps1
More file actions
35 lines (28 loc) · 1011 Bytes
/
normalizeAssetPaths.ps1
File metadata and controls
35 lines (28 loc) · 1011 Bytes
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
param(
[Parameter(Mandatory = $true)]
$root
)
function GetReplacements
{
param($relativePrefix)
@{
'"\/css\/' = "`"$relativePrefix/css/"
'"\/fonts\/' = "`"$relativePrefix/fonts/"
'"\/images\/' = "`"$relativePrefix/images/"
'"\/js\/' = "`"$relativePrefix/js/"
'"\/Archive\/' = "`"$relativePrefix/Archive/"
'"\/suttas\/' = "`"$relativePrefix/suttas/"
}
}
Get-ChildItem -rec -filt *.html $root | % {
"Fixing up {0}" -f $_.FullName;
Push-Location $_.DirectoryName;
$relativePrefix = (Join-Path $root "index.html" | Resolve-Path -Relative).Replace('index.html', '').Replace('\', '/').TrimEnd('/')
$contents = Get-Content $_ -Raw -Encoding utf8
$replacements = GetReplacements $relativePrefix
$replacements.Keys | ForEach-Object {
$contents = $contents -replace @($_,$replacements[$_])
}
[System.IO.File]::WriteAllText($_.FullName, $contents, [System.Text.UTF8Encoding]($False))
Pop-Location
}