29 lines (28 loc) · 1.45 KB
 1{{ with resources.Get "scss/main.scss" }}
 2  {{ $opts := dict
 3    "enableSourceMap" hugo.IsDevelopment
 4    "outputStyle" (cond hugo.IsDevelopment "expanded" "compressed")
 5    "targetPath" "css/main.css"
 6    "transpiler" "dartsass"
 7    "vars" site.Params.styles
 8    "includePaths" (slice "node_modules/bootstrap/scss")
 9  }}
10  {{ with . | toCSS $opts }}
11    {{ if hugo.IsDevelopment }}
12      <link rel="stylesheet" href="{{ .RelPermalink }}">
13    {{ else }}
14      {{ $min := . | minify }}
15      {{ $asset := $min | fingerprint }}
16      {{/* External, not inlined: the same fingerprinted URL on every page
17           means the browser fetches it once and reuses it from cache on
18           every other page, instead of re-downloading it inline each time.
19           onerror: a stylesheet can fail silently (flaky mobile connection,
20           a privacy browser stripping the request, a stale cached HTML
21           pointing at a fingerprint that's since rolled) leaving the page
22           fully unstyled with no visible sign anything went wrong. One
23           retry via reload; the flag stops a genuinely broken deploy from
24           reload-looping forever. */}}
25      <link rel="stylesheet" href="{{ $asset.RelPermalink }}" integrity="{{ $asset.Data.Integrity }}" crossorigin="anonymous" onerror="if(!sessionStorage.getItem('css-retry')){sessionStorage.setItem('css-retry','1');location.reload();}" onload="sessionStorage.removeItem('css-retry')">
26    {{ end }}
27  {{ end }}
28{{ end }}
29