提交 924692a0 编写于 作者: D Dillon

feat(assets): add SRI config for stylesheet and script

上级 ac08e077
...@@ -208,7 +208,7 @@ enableEmoji = true ...@@ -208,7 +208,7 @@ enableEmoji = true
# Disqus Comment Config (https://disqus.com/) # Disqus Comment Config (https://disqus.com/)
[languages.en.params.comment.disqus] [languages.en.params.comment.disqus]
# Disqus shortname to use Disqus in posts # Disqus shortname to use Disqus in posts
shortname = "dillonzq" shortname = ""
# Gittalk Comment Config (https://github.com/gitalk/gitalk) # Gittalk Comment Config (https://github.com/gitalk/gitalk)
[languages.en.params.comment.gitalk] [languages.en.params.comment.gitalk]
owner = "" owner = ""
...@@ -423,7 +423,7 @@ enableEmoji = true ...@@ -423,7 +423,7 @@ enableEmoji = true
# Disqus 评论系统设置 (https://disqus.com/) # Disqus 评论系统设置 (https://disqus.com/)
[languages.zh-CN.params.comment.disqus] [languages.zh-CN.params.comment.disqus]
# Disqus 的用户名,用来在文章中启用 Disqus 评论系统 # Disqus 的用户名,用来在文章中启用 Disqus 评论系统
shortname = "dillonzq" shortname = ""
# Gittalk 评论系统设置 (https://github.com/gitalk/gitalk) # Gittalk 评论系统设置 (https://github.com/gitalk/gitalk)
[languages.zh-CN.params.comment.gitalk] [languages.zh-CN.params.comment.gitalk]
owner = "" owner = ""
...@@ -638,7 +638,7 @@ enableEmoji = true ...@@ -638,7 +638,7 @@ enableEmoji = true
# Disqus Comment Config (https://disqus.com/) # Disqus Comment Config (https://disqus.com/)
[languages.fr.params.comment.disqus] [languages.fr.params.comment.disqus]
# Disqus shortname to use Disqus in posts # Disqus shortname to use Disqus in posts
shortname = "dillonzq" shortname = ""
# Gittalk Comment Config (https://github.com/gitalk/gitalk) # Gittalk Comment Config (https://github.com/gitalk/gitalk)
[languages.fr.params.comment.gitalk] [languages.fr.params.comment.gitalk]
owner = "" owner = ""
...@@ -674,6 +674,9 @@ enableEmoji = true ...@@ -674,6 +674,9 @@ enableEmoji = true
# public git repo url only then enableGitInfo is true # public git repo url only then enableGitInfo is true
# 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效 # 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效
gitRepo = "https://github.com/dillonzq/LoveIt" gitRepo = "https://github.com/dillonzq/LoveIt"
# which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5")
# 哪种哈希函数用来 SRI, 为空时表示不使用 SRI ("sha256", "sha384", "sha512", "md5")
fingerprint = ""
# Header info # Header info
# 页面头部导航栏信息 # 页面头部导航栏信息
[params.header] [params.header]
......
...@@ -193,6 +193,9 @@ Note that some of these parameters are explained in details in other sections of ...@@ -193,6 +193,9 @@ Note that some of these parameters are explained in details in other sections of
defaultTheme = "auto" defaultTheme = "auto"
# public git repo url only then enableGitInfo is true # public git repo url only then enableGitInfo is true
gitRepo = "" gitRepo = ""
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): v0.1.1
# which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5")
fingerprint = ""
# Header info # Header info
[params.header] [params.header]
# desktop header mode ("fixed", "normal", "auto") # desktop header mode ("fixed", "normal", "auto")
......
...@@ -198,6 +198,9 @@ Note that some of these parameters are explained in details in other sections of ...@@ -198,6 +198,9 @@ Note that some of these parameters are explained in details in other sections of
defaultTheme = "auto" defaultTheme = "auto"
# public git repo url only then enableGitInfo is true # public git repo url only then enableGitInfo is true
gitRepo = "" gitRepo = ""
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): v0.1.1
# which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5")
fingerprint = ""
# Header info # Header info
[params.header] [params.header]
# desktop header mode ("fixed", "normal", "auto") # desktop header mode ("fixed", "normal", "auto")
......
...@@ -193,6 +193,9 @@ hugo ...@@ -193,6 +193,9 @@ hugo
defaultTheme = "auto" defaultTheme = "auto"
# 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效 # 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效
gitRepo = "" gitRepo = ""
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): v0.1.1
# 哪种哈希函数用来 SRI, 为空时表示不使用 SRI ("sha256", "sha384", "sha512", "md5")
fingerprint = ""
# 页面头部导航栏信息 # 页面头部导航栏信息
[params.header] [params.header]
# 桌面端导航栏模式 ("fixed", "normal", "auto") # 桌面端导航栏模式 ("fixed", "normal", "auto")
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
{{- if eq hugo.Environment "production" -}} {{- if eq hugo.Environment "production" -}}
{{- $scratch.Set "production" true -}} {{- $scratch.Set "production" true -}}
{{- $scratch.Set "CDN" .Site.Params.cdn -}} {{- $scratch.Set "CDN" .Site.Params.cdn -}}
{{- $scratch.Set "fingerprint" .Site.Params.fingerprint -}}
{{- end -}} {{- end -}}
<!DOCTYPE html> <!DOCTYPE html>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
{{- /* Title */ -}} {{- /* Title */ -}}
<h1 class="single-title" itemprop="name headline"> <h1 class="single-title" itemprop="name headline">
<a href="{{ .Permalink }}">{{ .Title }}</a> <a href="{{ .RelPermalink }}">{{ .Title }}</a>
</h1> </h1>
{{- /* Meta */ -}} {{- /* Meta */ -}}
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
{{- /* Footer */ -}} {{- /* Footer */ -}}
<div class="post-footer"> <div class="post-footer">
<a href="{{ .Permalink }}">{{ T "readMore" }}</a> <a href="{{ .RelPermalink }}">{{ T "readMore" }}</a>
{{- with .Params.tags -}} {{- with .Params.tags -}}
<div class="post-tags"> <div class="post-tags">
{{- range . -}} {{- range . -}}
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
{{- end -}} {{- end -}}
{{- /* lightgallery.js */ -}} {{- /* 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 -}} {{- with $CDN.lightgalleryCSS -}}
{{- slice . | $scratch.Add "linkCDN" -}} {{- slice . | $scratch.Add "linkCDN" -}}
{{- else -}} {{- else -}}
...@@ -222,8 +222,8 @@ ...@@ -222,8 +222,8 @@
{{- else if not (strings.HasSuffix . ".min.css") -}} {{- else if not (strings.HasSuffix . ".min.css") -}}
{{- $res = minify $res -}} {{- $res = minify $res -}}
{{- end -}} {{- end -}}
{{- $res = $res | resources.Fingerprint "sha256" -}} {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> {{- partial "plugin/stylesheet.html" $stylesheet -}}
{{- end -}} {{- end -}}
{{- range $scratch.Get "scriptCDN" -}} {{- range $scratch.Get "scriptCDN" -}}
...@@ -234,8 +234,8 @@ ...@@ -234,8 +234,8 @@
{{- if not (strings.HasSuffix . ".min.js") -}} {{- if not (strings.HasSuffix . ".min.js") -}}
{{- $res = minify $res -}} {{- $res = minify $res -}}
{{- end -}} {{- end -}}
{{- $res = $res | resources.Fingerprint "sha256" -}} {{- $script := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}}
<script src="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"></script> {{- partial "plugin/script.html" $script -}}
{{- end -}} {{- end -}}
{{- /* Google analytics async */ -}} {{- /* Google analytics async */ -}}
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{{- /* Disqus Comment System */ -}} {{- /* Disqus Comment System */ -}}
{{- with .Site.Params.comment.disqus.shortname -}} {{- with .Site.Params.comment.disqus.shortname -}}
<div id="disqus_thread"></div> <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" -}} {{- slice $script | $scratch.Add "scriptCDN" -}}
<noscript> <noscript>
Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a> Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
......
...@@ -25,16 +25,18 @@ ...@@ -25,16 +25,18 @@
{{- with $CDN.fontawesomeFreeCSS -}} {{- with $CDN.fontawesomeFreeCSS -}}
{{- . | safeHTML -}} {{- . | safeHTML -}}
{{- else -}} {{- else -}}
{{- $res := resources.Get "lib/fontawesome-free/all.min.css" | resources.Fingerprint "sha256" -}} {{- $res := resources.Get "lib/fontawesome-free/all.min.css" -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}}
{{- partial "plugin/stylesheet.html" $stylesheet -}}
{{- end -}} {{- end -}}
{{- /* Animate.css */ -}} {{- /* Animate.css */ -}}
{{- with $CDN.animateCSS -}} {{- with $CDN.animateCSS -}}
{{- . | safeHTML -}} {{- . | safeHTML -}}
{{- else -}} {{- else -}}
{{ $res := resources.Get "lib/animate/animate.min.css" | resources.Fingerprint "sha256" -}} {{- $res := resources.Get "lib/fontawesome-free/all.min.css" -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}}
{{- partial "plugin/stylesheet.html" $stylesheet -}}
{{- end -}} {{- end -}}
{{- /* style.min.css */ -}} {{- /* style.min.css */ -}}
...@@ -43,5 +45,6 @@ ...@@ -43,5 +45,6 @@
{{- $options = dict "includePaths" (slice "config/css") | merge $options -}} {{- $options = dict "includePaths" (slice "config/css") | merge $options -}}
{{- $options = dict "outputStyle" "compressed" | merge $options -}} {{- $options = dict "outputStyle" "compressed" | merge $options -}}
{{- $options = dict "enableSourceMap" true | merge $options -}} {{- $options = dict "enableSourceMap" true | merge $options -}}
{{- $res = resources.ExecuteAsTemplate "style.scss" . $res | toCSS $options | resources.Fingerprint "sha256" -}} {{- $res = resources.ExecuteAsTemplate "style.scss" . $res | toCSS $options -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"> {{- $stylesheet := (dict "resource" $res "fingerprint" ($scratch.Get "fingerprint")) -}}
{{- partial "plugin/stylesheet.html" $stylesheet -}}
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
{{- range $.Site.Languages -}} {{- range $.Site.Languages -}}
{{- if eq $translation.Lang .Lang -}} {{- if eq $translation.Lang .Lang -}}
{{- if eq $.Page.Lang .Lang -}} {{- if eq $.Page.Lang .Lang -}}
<option value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option> <option value="{{ $translation.RelPermalink }}" selected>{{ .LanguageName }}</option>
{{- else -}} {{- else -}}
<option value="{{ $translation.Permalink }}">{{ .LanguageName }}</option> <option value="{{ $translation.RelPermalink }}">{{ .LanguageName }}</option>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
...@@ -68,9 +68,9 @@ ...@@ -68,9 +68,9 @@
{{- range $.Site.Languages -}} {{- range $.Site.Languages -}}
{{- if eq $translation.Lang .Lang -}} {{- if eq $translation.Lang .Lang -}}
{{- if eq $.Page.Lang .Lang -}} {{- if eq $.Page.Lang .Lang -}}
<option value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option> <option value="{{ $translation.RelPermalink }}" selected>{{ .LanguageName }}</option>
{{- else -}} {{- else -}}
<option value="{{ $translation.Permalink }}">{{ .LanguageName }}</option> <option value="{{ $translation.RelPermalink }}">{{ .LanguageName }}</option>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
......
{{- $res := .resource -}}
{{- with .fingerprint -}}
{{- $res = $res | resources.Fingerprint . -}}
<script src="{{ $res.RelPermalink }}" integrity="{{ $res.Data.Integrity }}"></script>
{{- else -}}
<script src="{{ $res.RelPermalink }}"></script>
{{- end -}}
{{- $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 -}}
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
{{- if ne .Site.Params.page.linkToMarkdown false | and (ne .Params.linkToMarkdown false) -}} {{- if ne .Site.Params.page.linkToMarkdown false | and (ne .Params.linkToMarkdown false) -}}
{{- with .OutputFormats.Get "markdown" -}} {{- with .OutputFormats.Get "markdown" -}}
<span> <span>
<a class="link-to-markdown" href="{{ .Permalink }}" target="_blank"> <a class="link-to-markdown" href="{{ .RelPermalink }}" target="_blank">
{{- T "seeMarkdown" -}} {{- T "seeMarkdown" -}}
</a> </a>
</span> </span>
...@@ -60,10 +60,10 @@ ...@@ -60,10 +60,10 @@
<div class="post-nav"> <div class="post-nav">
{{- if .PrevInSection -}} {{- 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 -}} {{- end -}}
{{ if .NextInSection }} {{ 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 -}} {{- end -}}
</div> </div>
</div> </div>
...@@ -23,20 +23,20 @@ ...@@ -23,20 +23,20 @@
<div class="card-item"> <div class="card-item">
<div class="card-item-wrapper"> <div class="card-item-wrapper">
<h3 class="card-item-title"> <h3 class="card-item-title">
<a href="{{ .Permalink }}"> <a href="{{ .RelPermalink }}">
<i class="far fa-folder fa-fw"></i>&nbsp;{{ $term | humanize}} <i class="far fa-folder fa-fw"></i>&nbsp;{{ $term | humanize}}
</a> </a>
</h3> </h3>
{{- range first 5 $pages -}} {{- range first 5 $pages -}}
<article class="archive-item"> <article class="archive-item">
<a href="{{ .Permalink }}" class="archive-item-link"> <a href="{{ .RelPermalink }}" class="archive-item-link">
{{- .Title -}} {{- .Title -}}
</a> </a>
</article> </article>
{{- end -}} {{- end -}}
{{- if gt (len $pages) 5 -}} {{- if gt (len $pages) 5 -}}
<span class="more-post"> <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> </span>
{{- end -}} {{- end -}}
</div> </div>
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
{{- else if eq $taxonomies "tags" -}} {{- else if eq $taxonomies "tags" -}}
<div class="tag-cloud-tags"> <div class="tag-cloud-tags">
{{- range $.Site.Taxonomies.tags.ByCount -}} {{- 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 -}} {{- end -}}
</div> </div>
{{- end -}} {{- end -}}
......
{ {
"name": "loveit-src", "name": "loveit-src",
"version": "0.1.0", "version": "0.1.1",
"description": "LoveIt theme source file", "description": "LoveIt theme source file",
"main": "index.js", "main": "index.js",
"dependencies": {}, "dependencies": {},
......
{"Target":"css/style.min.8596c27951d415c1b2ad9aee1d642e8057049327eca5ce9e397bdd27d84ca62a.css","MediaType":"text/css","Data":{"Integrity":"sha256-hZbCeVHUFcGyrZruHWQugFcEkyfspc6eOXvdJ9hMpio="}}
\ No newline at end of file
{"Target":"css/style.min.css","MediaType":"text/css","Data":{}}
\ No newline at end of file
{"Target":"lib/aplayer/dark.css","MediaType":"text/css","Data":{}}
\ No newline at end of file
{"Target":"lib/aplayer/dark.cf3d10211c52ef53113d7dc3ab708c366141ee4459043a50b02215bc8a2ef76a.css","MediaType":"text/css","Data":{"Integrity":"sha256-zz0QIRxS71MRPX3Dq3CMNmFB7kRZBDpQsCIVvIou92o="}}
\ No newline at end of file
{"Target":"lib/mermaid/mermaid.css","MediaType":"text/css","Data":{}}
\ No newline at end of file
{"Target":"lib/mermaid/mermaid.828bd139deac55c048b4d9ed77d849196aada4a0ea2268d7c59946e8d71665b7.css","MediaType":"text/css","Data":{"Integrity":"sha256-govROd6sVcBItNntd9hJGWqtpKDqImjXxZlG6NcWZbc="}}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册