head-css.html 1.0 KB

123456789101112131415161718192021222324252627282930
  1. {{ $scssMain := "scss/main.scss" -}}
  2. {{ $css := resources.Get $scssMain
  3. | toCSS (dict "enableSourceMap" (not hugo.IsProduction)) -}}
  4. {{/* NOTE: we only apply `postCSS` in production or for RTL languages. This
  5. makes it snappier to develop in Chrome, but it may look sub-optimal in other
  6. browsers. */ -}}
  7. {{ if eq .Site.Language.LanguageDirection "rtl" -}}
  8. {{ $css = $css
  9. | postCSS (dict "use" "autoprefixer rtlcss" "noMap" true)
  10. | resources.Copy (replace $scssMain "." ".rtl.") -}}
  11. {{ else if hugo.IsProduction -}}
  12. {{ $css = $css | postCSS -}}
  13. {{ end -}}
  14. {{ if hugo.IsProduction -}}
  15. {{ $css = $css | minify | fingerprint -}}
  16. <link rel="preload" href="{{ $css.RelPermalink }}" as="style" integrity="{{ $css.Data.Integrity }}" crossorigin="anonymous">
  17. {{ end -}}
  18. {{ with $css -}}
  19. <link href="{{ .RelPermalink }}" rel="stylesheet"
  20. {{- with .Data.Integrity }} integrity="{{ . }}" crossorigin="anonymous"{{ end -}}
  21. >
  22. {{ else -}}
  23. {{ errorf "Resource not found or error building CSS: %s" $scssMain -}}
  24. {{ end -}}
  25. {{- /**/ -}}