mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
17164f42d0
- Replace legacy service-worker.js (imported from DoIt) with a clean rewrite using Hugo's ExecuteAsTemplate for fingerprinted URL injection - Cache-first for static assets (immutable/fingerprinted), network-first for HTML pages with LRU eviction (max 100 entries) - Fix LRU eviction to protect precached URLs using absolute URL comparison - Add Fingerprint param to js-build.html partial to reduce boilerplate - Extract to-css.html partial for reusable SCSS-to-CSS pipeline - Support pre-built Resource param in script.html and style.html - Store mainCSS and mainJS in Site.Store to avoid duplicate builds - Remove explicit scope from serviceWorker.register() (defaults to /) Closes #298
33 lines
1.1 KiB
HTML
33 lines
1.1 KiB
HTML
{{- /*
|
|
Build and minify a JS resource with unified behavior.
|
|
@param {resource.Resource} .Resource Hugo resource to process
|
|
@param {Object|Boolean} [.Build] true for defaults, dict for custom options, false/omit to skip js.Build
|
|
@param {Boolean} [.Minify] extra minify flag; final minify is Minify OR Build.minify
|
|
@param {String} [.Fingerprint] fingerprint algorithm (e.g. "sha256")
|
|
@return {resource.Resource}
|
|
*/ -}}
|
|
|
|
{{- $resource := .Resource -}}
|
|
{{- $minify := .Minify -}}
|
|
{{- with .Build -}}
|
|
{{- $defaultOptions := dict
|
|
"targetPath" (replaceRE `\.(template\.)?ts$` ".js" $resource.Name)
|
|
"sourceMap" (cond hugo.IsDevelopment "linked" "none")
|
|
"minify" hugo.IsProduction
|
|
-}}
|
|
{{- $options := . -}}
|
|
{{- if eq . true -}}
|
|
{{- $options = dict -}}
|
|
{{- end -}}
|
|
{{- $options = $options | merge $defaultOptions -}}
|
|
{{- $resource = $resource | js.Build $options -}}
|
|
{{- $minify = $minify | or (index $options "minify") -}}
|
|
{{- end -}}
|
|
{{- if $minify -}}
|
|
{{- $resource = $resource | minify -}}
|
|
{{- end -}}
|
|
{{- with .Fingerprint -}}
|
|
{{- $resource = $resource | fingerprint . -}}
|
|
{{- end -}}
|
|
{{- return $resource -}}
|