diff options
author | Dillon <dillonzq@outlook.com> | 2020-03-09 15:25:55 +0300 |
---|---|---|
committer | Dillon <dillonzq@outlook.com> | 2020-03-09 15:25:55 +0300 |
commit | 924692a07efd5fc430cefb3a1a2e3561570b9d33 (patch) | |
tree | d18915dc2e530450e1819ce7e604382cd9f44f23 /layouts | |
parent | ac08e0776e719377365d99a42b4fabbf657b9f18 (diff) |
feat(assets): add SRI config for stylesheet and script
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/_default/baseof.html | 1 | ||||
-rw-r--r-- | layouts/_default/summary.html | 4 | ||||
-rw-r--r-- | layouts/partials/assets.html | 10 | ||||
-rw-r--r-- | layouts/partials/comment.html | 2 | ||||
-rw-r--r-- | layouts/partials/head/link.html | 15 | ||||
-rw-r--r-- | layouts/partials/header.html | 8 | ||||
-rw-r--r-- | layouts/partials/plugin/script.html | 7 | ||||
-rw-r--r-- | layouts/partials/plugin/stylesheet.html | 7 | ||||
-rw-r--r-- | layouts/partials/single/footer.html | 6 | ||||
-rw-r--r-- | layouts/taxonomy/terms.html | 8 |
10 files changed, 43 insertions, 25 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 90f5b6f..80eac99 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -8,6 +8,7 @@ {{- if eq hugo.Environment "production" -}} {{- $scratch.Set "production" true -}} {{- $scratch.Set "CDN" .Site.Params.cdn -}} + {{- $scratch.Set "fingerprint" .Site.Params.fingerprint -}} {{- end -}} <!DOCTYPE html> diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html index ee74fc7..cd95510 100644 --- a/layouts/_default/summary.html +++ b/layouts/_default/summary.html @@ -11,7 +11,7 @@ {{- /* Title */ -}} <h1 class="single-title" itemprop="name headline"> - <a href="{{ .Permalink }}">{{ .Title }}</a> + <a href="{{ .RelPermalink }}">{{ .Title }}</a> </h1> {{- /* Meta */ -}} @@ -55,7 +55,7 @@ {{- /* Footer */ -}} <div class="post-footer"> - <a href="{{ .Permalink }}">{{ T "readMore" }}</a> + <a href="{{ .RelPermalink }}">{{ T "readMore" }}</a> {{- with .Params.tags -}} <div class="post-tags"> {{- range . -}} diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index aa901c5..9ff4cd4 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -35,7 +35,7 @@ {{- end -}} {{- /* lightgallery.js */ -}} -{{- if ne .Page.Site.Params.page.lightgallery false | and (ne .Page.Params.lightgallery false) -}} +{{- if ne .Site.Params.page.lightgallery false | and (ne .Params.lightgallery false) -}} {{- with $CDN.lightgalleryCSS -}} {{- slice . | $scratch.Add "linkCDN" -}} {{- else -}} @@ -222,8 +222,8 @@ {{- else if not (strings.HasSuffix . ".min.css") -}} {{- $res = minify $res -}} {{- end -}} - {{- $res = $res | resources.Fingerprint "sha256" -}} - <link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> + {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}} + {{- partial "plugin/stylesheet.html" $stylesheet -}} {{- end -}} {{- range $scratch.Get "scriptCDN" -}} @@ -234,8 +234,8 @@ {{- if not (strings.HasSuffix . ".min.js") -}} {{- $res = minify $res -}} {{- end -}} - {{- $res = $res | resources.Fingerprint "sha256" -}} - <script src="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"></script> + {{- $script := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}} + {{- partial "plugin/script.html" $script -}} {{- end -}} {{- /* Google analytics async */ -}} diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html index 14b2cf4..b24ab1a 100644 --- a/layouts/partials/comment.html +++ b/layouts/partials/comment.html @@ -6,7 +6,7 @@ {{- /* Disqus Comment System */ -}} {{- with .Site.Params.comment.disqus.shortname -}} <div id="disqus_thread"></div> - {{- $script := printf `<script src="https://%s.disqus.com/embed.js"></script>` . -}} + {{- $script := printf `<script defer src="https://%s.disqus.com/embed.js"></script>` . -}} {{- slice $script | $scratch.Add "scriptCDN" -}} <noscript> Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a> diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index 9b007ec..316e91e 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -25,16 +25,18 @@ {{- with $CDN.fontawesomeFreeCSS -}} {{- . | safeHTML -}} {{- else -}} - {{- $res := resources.Get "lib/fontawesome-free/all.min.css" | resources.Fingerprint "sha256" -}} - <link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> + {{- $res := resources.Get "lib/fontawesome-free/all.min.css" -}} + {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}} + {{- partial "plugin/stylesheet.html" $stylesheet -}} {{- end -}} {{- /* Animate.css */ -}} {{- with $CDN.animateCSS -}} {{- . | safeHTML -}} {{- else -}} - {{ $res := resources.Get "lib/animate/animate.min.css" | resources.Fingerprint "sha256" -}} - <link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> + {{- $res := resources.Get "lib/fontawesome-free/all.min.css" -}} + {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}} + {{- partial "plugin/stylesheet.html" $stylesheet -}} {{- end -}} {{- /* style.min.css */ -}} @@ -43,5 +45,6 @@ {{- $options = dict "includePaths" (slice "config/css") | merge $options -}} {{- $options = dict "outputStyle" "compressed" | merge $options -}} {{- $options = dict "enableSourceMap" true | merge $options -}} -{{- $res = resources.ExecuteAsTemplate "style.scss" . $res | toCSS $options | resources.Fingerprint "sha256" -}} -<link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> +{{- $res = resources.ExecuteAsTemplate "style.scss" . $res | toCSS $options -}} +{{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}} +{{- partial "plugin/stylesheet.html" $stylesheet -}} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index d4b0951..a2db93e 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -22,9 +22,9 @@ {{- range $.Site.Languages -}} {{- if eq $translation.Lang .Lang -}} {{- if eq $.Page.Lang .Lang -}} - <option value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option> + <option value="{{ $translation.RelPermalink }}" selected>{{ .LanguageName }}</option> {{- else -}} - <option value="{{ $translation.Permalink }}">{{ .LanguageName }}</option> + <option value="{{ $translation.RelPermalink }}">{{ .LanguageName }}</option> {{- end -}} {{- end -}} {{- end -}} @@ -68,9 +68,9 @@ {{- range $.Site.Languages -}} {{- if eq $translation.Lang .Lang -}} {{- if eq $.Page.Lang .Lang -}} - <option value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option> + <option value="{{ $translation.RelPermalink }}" selected>{{ .LanguageName }}</option> {{- else -}} - <option value="{{ $translation.Permalink }}">{{ .LanguageName }}</option> + <option value="{{ $translation.RelPermalink }}">{{ .LanguageName }}</option> {{- end -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/plugin/script.html b/layouts/partials/plugin/script.html new file mode 100644 index 0000000..92a8bdc --- /dev/null +++ b/layouts/partials/plugin/script.html @@ -0,0 +1,7 @@ +{{- $res := .resource -}} +{{- with .fingerprint -}} + {{- $res = $res | resources.Fingerprint . -}} + <script src="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"></script> +{{- else -}} + <script src="{{ $res.RelPermalink }}"></script> +{{- end -}} diff --git a/layouts/partials/plugin/stylesheet.html b/layouts/partials/plugin/stylesheet.html new file mode 100644 index 0000000..22db6d4 --- /dev/null +++ b/layouts/partials/plugin/stylesheet.html @@ -0,0 +1,7 @@ +{{- $res := .resource -}} +{{- with .fingerprint -}} + {{- $res = $res | resources.Fingerprint . -}} + <link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> +{{- else -}} + <link rel="stylesheet" href="{{ $res.RelPermalink }}"> +{{- end -}} diff --git a/layouts/partials/single/footer.html b/layouts/partials/single/footer.html index af0efeb..18d7d7f 100644 --- a/layouts/partials/single/footer.html +++ b/layouts/partials/single/footer.html @@ -26,7 +26,7 @@ {{- if ne .Site.Params.page.linkToMarkdown false | and (ne .Params.linkToMarkdown false) -}} {{- with .OutputFormats.Get "markdown" -}} <span> - <a class="link-to-markdown" href="{{ .Permalink }}" target="_blank"> + <a class="link-to-markdown" href="{{ .RelPermalink }}" target="_blank"> {{- T "seeMarkdown" -}} </a> </span> @@ -60,10 +60,10 @@ <div class="post-nav"> {{- if .PrevInSection -}} - <a href="{{ .PrevInSection.Permalink }}" class="prev" rel="prev" title="{{ .PrevInSection.Title }}"><i class="fas fa-angle-left fa-fw"></i>{{ .PrevInSection.Title }}</a> + <a href="{{ .PrevInSection.RelPermalink }}" class="prev" rel="prev" title="{{ .PrevInSection.Title }}"><i class="fas fa-angle-left fa-fw"></i>{{ .PrevInSection.Title }}</a> {{- end -}} {{ if .NextInSection }} - <a href="{{ .NextInSection.Permalink }}" class="next" rel="next" title="{{ .NextInSection.Title }}">{{ .NextInSection.Title }}<i class="fas fa-angle-right fa-fw"></i></a> + <a href="{{ .NextInSection.RelPermalink }}" class="next" rel="next" title="{{ .NextInSection.Title }}">{{ .NextInSection.Title }}<i class="fas fa-angle-right fa-fw"></i></a> {{- end -}} </div> </div> diff --git a/layouts/taxonomy/terms.html b/layouts/taxonomy/terms.html index 8faaf2b..d1a7f95 100644 --- a/layouts/taxonomy/terms.html +++ b/layouts/taxonomy/terms.html @@ -23,20 +23,20 @@ <div class="card-item"> <div class="card-item-wrapper"> <h3 class="card-item-title"> - <a href="{{ .Permalink }}"> + <a href="{{ .RelPermalink }}"> <i class="far fa-folder fa-fw"></i> {{ $term | humanize}} </a> </h3> {{- range first 5 $pages -}} <article class="archive-item"> - <a href="{{ .Permalink }}" class="archive-item-link"> + <a href="{{ .RelPermalink }}" class="archive-item-link"> {{- .Title -}} </a> </article> {{- end -}} {{- if gt (len $pages) 5 -}} <span class="more-post"> - <a href="{{ .Permalink }}" class="more-single-link">{{ T "more" }} >></a> + <a href="{{ .RelPermalink }}" class="more-single-link">{{ T "more" }} >></a> </span> {{- end -}} </div> @@ -49,7 +49,7 @@ {{- else if eq $taxonomies "tags" -}} <div class="tag-cloud-tags"> {{- range $.Site.Taxonomies.tags.ByCount -}} - <a href="{{ .Page.Permalink }}"> {{ .Page.Title }} <small>({{ .Count }})</small></a> + <a href="{{ .Page.RelPermalink }}"> {{ .Page.Title }} <small>({{ .Count }})</small></a> {{- end -}} </div> {{- end -}} |