Files
FixIt/layouts/_partials/function/to-css.html
T
Cell 17164f42d0 fix(assets): rewrite service worker with two-strategy caching (#774)
- 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
2026-05-31 17:54:02 +08:00

36 lines
1.3 KiB
HTML

{{- /*
Compile SCSS to CSS via dartsass, optionally minify and fingerprint.
@param {resource.Resource} .Resource SCSS resource
@param {Object|Boolean} [.ToCSS] true for defaults, dict for custom toCSS options, false/omit to skip
@param {Boolean} [.Minify] whether to minify; defaults to hugo.IsProduction when ToCSS is used
@param {String} [.Fingerprint] fingerprint algorithm (e.g. "sha256")
@return {resource.Resource}
*/ -}}
{{- $resource := .Resource -}}
{{- $minify := .Minify -}}
{{- with .ToCSS -}}
{{- $targetPath := replaceRE `\.(template\.)?scss$` ".css" $resource.Name -}}
{{- $targetPath = replace $targetPath "scss" "css" -}}
{{- $defaultOptions := dict
"transpiler" "dartsass"
"enableSourceMap" hugo.IsDevelopment
"outputStyle" (cond hugo.IsDevelopment "expanded" "compressed")
"targetPath" $targetPath
-}}
{{- $options := . -}}
{{- if eq $options true -}}
{{- $options = dict -}}
{{- end -}}
{{- $options = $options | merge $defaultOptions -}}
{{- $resource = $resource | toCSS $options -}}
{{- $minify = $minify | default hugo.IsProduction -}}
{{- end -}}
{{- if $minify -}}
{{- $resource = $resource | minify -}}
{{- end -}}
{{- with .Fingerprint -}}
{{- $resource = $resource | fingerprint . -}}
{{- end -}}
{{- return $resource -}}