hugo-bearblog : add option to diable integrity using papermod's solution

This commit is contained in:
minoplhy 2024-03-10 13:18:57 +07:00
parent b46dab5ba6
commit 1c1dd34eb2
Signed by: minoplhy
GPG Key ID: 41D406044E2434BF
3 changed files with 36 additions and 11 deletions

View File

@ -50,3 +50,8 @@ ignoreErrors = ["error-disable-taxonomy"]
# for details. An example TOML config that uses [ISO
# 8601](https://en.wikipedia.org/wiki/ISO_8601) format:
# dateFormat = "2006-01-02"
# based on solutions by papermod : https://github.com/adityatelange/hugo-PaperMod/issues/89
# disable integrity on script,stylesheet linking
[params.assets]
# disableFingerprinting = true

View File

@ -15,14 +15,25 @@
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ end -}}
<!-- External Script, Stylesheet linking -->
{{- /* CSS stylesheet */}}
{{- $stylesheet := (resources.Get "css/style.css") | resources.Minify | fingerprint }}
<link crossorigin="anonymous" href="{{ $stylesheet.RelPermalink }}" integrity="{{ $stylesheet.Data.Integrity }}" rel="preload stylesheet" as="style">
{{- $stylesheet := (resources.Get "css/style.css") | resources.Minify }}
{{- if not site.Params.assets.disableFingerprinting }}
{{- $stylesheet := $stylesheet | fingerprint }}
<link crossorigin="anonymous" href="{{ $stylesheet.RelPermalink }}" integrity="{{ $stylesheet.Data.Integrity }}" rel="preload stylesheet" as="style">
{{ else }}
<link crossorigin="anonymous" href="{{ $stylesheet.RelPermalink }}" rel="preload stylesheet" as="style">
{{ end }}
{{- /* Javascript */}}
{{- $darkmode_script := (resources.Get "js/darkmode.js") | resources.Minify | fingerprint}}
<script defer crossorigin="anonymous" src="{{ $darkmode_script.RelPermalink }}" integrity="{{ $darkmode_script.Data.Integrity }}" async></script>
{{- $darkmode_script := (resources.Get "js/darkmode.js") | resources.Minify }}
{{- if not site.Params.assets.disableFingerprinting }}
{{- $darkmode_script := $darkmode_script | fingerprint }}
<script async crossorigin="anonymous" src="{{ $darkmode_script.RelPermalink }}" integrity="{{ $darkmode_script.Data.Integrity }}"></script>
{{ else }}
<script async crossorigin="anonymous" src="{{ $darkmode_script.RelPermalink }}"></script>
{{ end }}
<!-- A partial to be overwritten by the user.
Simply place a custom_head.html into
your local /layouts/partials-directory -->
@ -41,9 +52,14 @@
</footer>
{{- /* Bottom Javascript */}}
{{- $darkmode_load_script := (resources.Get "js/darkmode_load.js") | resources.Minify | fingerprint}}
<script defer crossorigin="anonymous" src="{{ $darkmode_load_script.RelPermalink }}" integrity="{{ $darkmode_load_script.Data.Integrity }}"></script>
{{- $darkmode_load_script := (resources.Get "js/darkmode_load.js") | resources.Minify}}
{{- if not site.Params.assets.disableFingerprinting }}
{{- $darkmode_load_script := $darkmode_load_script | fingerprint }}
<script async crossorigin="anonymous" src="{{ $darkmode_load_script.RelPermalink }}" integrity="{{ $darkmode_load_script.Data.Integrity }}"></script>
{{ else }}
<script async crossorigin="anonymous" src="{{ $darkmode_load_script.RelPermalink }}"></script>
{{ end }}
<!-- A partial to be overwritten by the user.
Simply place a custom_body.html into
your local /layouts/partials-directory -->

View File

@ -28,9 +28,13 @@
</ul>
{{- /* Random Color Script */}}
{{- $random_color_script := (resources.Get "js/random_color.js") | resources.Minify | fingerprint}}
<script defer crossorigin="anonymous" src="{{ $random_color_script.RelPermalink }}" integrity="{{ $random_color_script.Data.Integrity }}" async></script>
{{- $random_color_script := (resources.Get "js/random_color.js") | resources.Minify }}
{{- if not site.Params.assets.disableFingerprinting }}
{{- $random_color_script := $random_color_script | fingerprint }}
<script async crossorigin="anonymous" src="{{ $random_color_script.RelPermalink }}" integrity="{{ $random_color_script.Data.Integrity }}"></script>
{{ else }}
<script async crossorigin="anonymous" src="{{ $random_color_script.RelPermalink }}"></script>
{{ end }}
{{ if .Data.Singular }}
{{else}}