Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
feat(assets): add SRI config for stylesheet and script
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed Mar 9, 2020
1 parent ac08e07 commit 924692a
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 32 deletions.
9 changes: 6 additions & 3 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ enableEmoji = true
# Disqus Comment Config (https://disqus.com/)
[languages.en.params.comment.disqus]
# Disqus shortname to use Disqus in posts
shortname = "dillonzq"
shortname = ""
# Gittalk Comment Config (https://github.com/gitalk/gitalk)
[languages.en.params.comment.gitalk]
owner = ""
Expand Down Expand Up @@ -423,7 +423,7 @@ enableEmoji = true
# Disqus 评论系统设置 (https://disqus.com/)
[languages.zh-CN.params.comment.disqus]
# Disqus 的用户名,用来在文章中启用 Disqus 评论系统
shortname = "dillonzq"
shortname = ""
# Gittalk 评论系统设置 (https://github.com/gitalk/gitalk)
[languages.zh-CN.params.comment.gitalk]
owner = ""
Expand Down Expand Up @@ -638,7 +638,7 @@ enableEmoji = true
# Disqus Comment Config (https://disqus.com/)
[languages.fr.params.comment.disqus]
# Disqus shortname to use Disqus in posts
shortname = "dillonzq"
shortname = ""
# Gittalk Comment Config (https://github.com/gitalk/gitalk)
[languages.fr.params.comment.gitalk]
owner = ""
Expand Down Expand Up @@ -674,6 +674,9 @@ enableEmoji = true
# public git repo url only then enableGitInfo is true
# 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效
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
# 页面头部导航栏信息
[params.header]
Expand Down
3 changes: 3 additions & 0 deletions exampleSite/content/posts/theme-documentation-basics.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ Note that some of these parameters are explained in details in other sections of
defaultTheme = "auto"
# public git repo url only then enableGitInfo is true
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
[params.header]
# desktop header mode ("fixed", "normal", "auto")
Expand Down
3 changes: 3 additions & 0 deletions exampleSite/content/posts/theme-documentation-basics.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ Note that some of these parameters are explained in details in other sections of
defaultTheme = "auto"
# public git repo url only then enableGitInfo is true
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
[params.header]
# desktop header mode ("fixed", "normal", "auto")
Expand Down
3 changes: 3 additions & 0 deletions exampleSite/content/posts/theme-documentation-basics.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ hugo
defaultTheme = "auto"
# 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效
gitRepo = ""
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): v0.1.1
# 哪种哈希函数用来 SRI, 为空时表示不使用 SRI ("sha256", "sha384", "sha512", "md5")
fingerprint = ""
# 页面头部导航栏信息
[params.header]
# 桌面端导航栏模式 ("fixed", "normal", "auto")
Expand Down
1 change: 1 addition & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{{- /* Title */ -}}
<h1 class="single-title" itemprop="name headline">
<a href="{{ .Permalink }}">{{ .Title }}</a>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</h1>

{{- /* Meta */ -}}
Expand Down Expand Up @@ -55,7 +55,7 @@ <h1 class="single-title" itemprop="name headline">

{{- /* 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 . -}}
Expand Down
10 changes: 5 additions & 5 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -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" -}}
Expand All @@ -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 */ -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
15 changes: 9 additions & 6 deletions layouts/partials/head/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ -}}
Expand All @@ -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 -}}
8 changes: 4 additions & 4 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -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 -}}
Expand Down
7 changes: 7 additions & 0 deletions layouts/partials/plugin/script.html
Original file line number Diff line number Diff line change
@@ -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 -}}
7 changes: 7 additions & 0 deletions layouts/partials/plugin/stylesheet.html
Original file line number Diff line number Diff line change
@@ -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 -}}
6 changes: 3 additions & 3 deletions layouts/partials/single/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
8 changes: 4 additions & 4 deletions layouts/taxonomy/terms.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ <h2 class="single-title animated pulse faster">
<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>&nbsp;{{ $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>
Expand All @@ -49,7 +49,7 @@ <h3 class="card-item-title">
{{- 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 -}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loveit-src",
"version": "0.1.0",
"version": "0.1.1",
"description": "LoveIt theme source file",
"main": "index.js",
"dependencies": {},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Target":"css/style.min.css","MediaType":"text/css","Data":{}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Target":"lib/aplayer/dark.css","MediaType":"text/css","Data":{}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Target":"lib/mermaid/mermaid.css","MediaType":"text/css","Data":{}}

This file was deleted.

0 comments on commit 924692a

Please sign in to comment.