diff --git a/.devtools/sethooks.ps1 b/.devtools/sethooks.ps1 new file mode 100644 index 0000000..930a120 --- /dev/null +++ b/.devtools/sethooks.ps1 @@ -0,0 +1,4 @@ +git config core.eol lf +git config core.autocrlf input + +git config core.hooksPath .githooks/windows \ No newline at end of file diff --git a/.devtools/updatehashes.ps1 b/.devtools/updatehashes.ps1 new file mode 100644 index 0000000..afd8f26 --- /dev/null +++ b/.devtools/updatehashes.ps1 @@ -0,0 +1,27 @@ +# Updates html files with cache busting urls including file hashes. + +# Actual file processing +$htmlfiles = Get-ChildItem -Path . -Recurse -Filter "*.html" | Resolve-path -relative +foreach ($htmlfile in $htmlfiles) { + Write-Host "[info] Processing '${htmlfile}' for cache busting..." -ForegroundColor Blue + + $resfiles = (@(Get-ChildItem -Path . -Recurse -Filter "*.css") + (Get-ChildItem -Path . -Recurse -Filter "*.js")) | Resolve-Path -relative + + if ($args[0] -eq "gitadd") { + $resfiles = (git status -s | Select-String -Pattern "[A-Z] .+") | ForEach-Object { -split $_.Line | Select-Object -Last 1 } + } + + foreach ($resfile in $resfiles) { + $resfile = $resfile -replace '\\', '/' -replace '\./', '' + # Check if resource is used in html file + if ($null -ne (Select-String -Path $htmlfile -Pattern $resfile)) { + $hash = (Get-FileHash $resfile -Algorithm SHA1).Hash + + # This is just for cache busting... + # If 7 first characters of SHA1 is okay for git, it should be more than enough for us + $hash = $hash.Substring(0, 7).ToLower() + + (Get-Content -Raw -Path $htmlfile).replace('\r\n', "\n") -replace "$resfile(\?v=[a-z0-9]+)?", "${resfile}?v=$hash" | Set-Content $htmlfile + } + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..07764a7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf \ No newline at end of file diff --git a/index.html b/index.html index b58a5dd..9491f31 100644 --- a/index.html +++ b/index.html @@ -4,22 +4,22 @@