Add asset fingerprinting and SRI

This commit is contained in:
James Panther
2021-08-21 12:20:29 +10:00
parent d022bc8df7
commit 444dbcd3ca
6 changed files with 2776 additions and 24 deletions
+28 -9
View File
@@ -27,16 +27,35 @@
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ end -}}
{{/* Styles */}}
{{ $cssScheme := resources.Get (printf "css/schemes/%s.css" (.Site.Params.colorScheme | default "congo")) }}
{{ if not $cssScheme }}
{{ $cssScheme = resources.Get "css/schemes/congo.css" }}
{{ $schemeCSS := resources.Get (printf "css/schemes/%s.css" (.Site.Params.colorScheme | default "congo")) }}
{{ if not $schemeCSS }}
{{ $schemeCSS = resources.Get "css/schemes/congo.css" }}
{{ end }}
{{ $schemeStyles := $schemeCSS | resources.Minify | resources.Fingerprint "sha512" }}
<link
type="text/css"
rel="stylesheet"
href="{{ $schemeStyles.Permalink }}"
integrity="{{ $schemeStyles.Data.Integrity }}"
/>
{{ $mainCSS := resources.Get "css/compiled/main.css" }}
{{ $mainStyles := $mainCSS | resources.Minify | resources.Fingerprint "sha512" }}
<link
type="text/css"
rel="stylesheet"
href="{{ $mainStyles.Permalink }}"
integrity="{{ $mainStyles.Data.Integrity }}"
/>
{{ $customCSS := resources.Get "css/custom.css" }}
{{ if $customCSS }}
{{ $customStyles := $customCSS | resources.Minify | resources.Fingerprint "sha512" }}
<link
type="text/css"
rel="stylesheet"
href="{{ $customStyles.Permalink }}"
integrity="{{ $customStyles.Data.Integrity }}"
/>
{{ end }}
{{ $stylesheet := $cssScheme | resources.Minify }}
<link type="text/css" rel="stylesheet" href="{{ $stylesheet.Permalink }}" />
<link type="text/css" rel="stylesheet" href="{{ "css/main.css" | absURL }}" />
{{ if (fileExists "static/css/custom.css") -}}
<link type="text/css" rel="stylesheet" href="{{ "css/custom.css" | absURL }}" />
{{- end }}
{{/* Icons */}}
{{ if templates.Exists "partials/favicons.html" }}
{{ partialCached "favicons.html" .Site }}