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

Commit

Permalink
fix: fix css and js cros bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed Aug 22, 2019
1 parent 934c3a5 commit c8bb077
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion assets/js/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jQuery(function($) {
this._linkToc();
this._initToc();
// Listen for orientation changes
window.addEventListener("orientationchange", function() {
window.addEventListener("resize", function() {
this.setTimeout(_Blog._initToc, 0);
}, false);
}
Expand Down
14 changes: 8 additions & 6 deletions layouts/partials/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.gitalk_css }}
{{ .Site.Params.cdn.gitalk_css | safeHTML }}
{{ else }}
{{- $secureRes := resources.Get "css/lib/gitalk/gitalk.css" | resources.Minify | resources.Fingerprint "sha512" -}}
<link rel="stylesheet" href="{{ $secureRes.RelPermalink }}" integrity="{{ $secureRes.Data.Integrity }}">
{{- $res := resources.Get "css/lib/gitalk/gitalk.css" | resources.Minify -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}">
{{ end }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.gitalk_js }}
{{ .Site.Params.cdn.gitalk_js | safeHTML }}
{{ else }}
{{- $secureRes := resources.Get "js/lib/gitalk/gitalk.min.js" | resources.Minify | resources.Fingerprint "sha512" -}}
<script src="{{ $secureRes.RelPermalink }}" integrity="{{ $secureRes.Data.Integrity }}"></script>
{{- $res := resources.Get "js/lib/gitalk/gitalk.min.js" | resources.Minify -}}
<script src="{{ $res.RelPermalink }}"></script>
{{ end }}
<script type="text/javascript">
var gitalk = new Gitalk({
Expand All @@ -56,8 +56,10 @@
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.valine_js }}
{{ .Site.Params.cdn.valine_js | safeHTML }}
{{ else }}
{{- $secureRes := resources.Get "js/lib/valine/Valine.min.js" | resources.Minify | resources.Fingerprint "sha512" -}}
<script src="{{ $secureRes.RelPermalink }}" integrity="{{ $secureRes.Data.Integrity }}"></script>
{{- $res := resources.Get "js/lib/valine/Valine.min.js" | resources.Minify -}}
{{ .Site.Params.cdn.fontawesome_free_css | safeHTML }}
{{ .Site.Params.cdn.fontawesome_free_css | safeHTML }}
<script src="{{ $res.RelPermalink }}"></script>
{{ end }}
<script type="text/javascript">
new Valine({
Expand Down
8 changes: 4 additions & 4 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@

{{- partial "seo_schema.html" . -}}

{{- $secureRes := resources.Get "css/style.scss" | resources.ToCSS | resources.Minify | resources.Fingerprint "sha512" -}}
<link rel="stylesheet" href="{{ $secureRes.RelPermalink }}" integrity="{{ $secureRes.Data.Integrity }}">
{{- $res := resources.Get "css/style.scss" | resources.ToCSS | resources.Minify -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}">
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.fontawesome_free_css }}
{{ .Site.Params.cdn.fontawesome_free_css | safeHTML }}
{{ else }}
{{- $secureRes := resources.Get "css/lib/fontawesome-free/all.min.css" | resources.Minify | resources.Fingerprint "sha512" -}}
<link rel="stylesheet" href="{{ $secureRes.RelPermalink }}" integrity="{{ $secureRes.Data.Integrity }}">
{{- $res := resources.Get "css/lib/fontawesome-free/all.min.css" | resources.Minify | resources.Fingerprint "sha512" -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}">
{{ end }}
55 changes: 26 additions & 29 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,99 +1,96 @@
{{ $secureCSS := "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\">" }}
{{ $secureJS := "<script src=\"%s\" integrity=\"%s\"></script>" }}

<!-- jQuery https://github.com/jquery/jquery -->
{{ $jquery := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.jquery_js }}
{{ $jquery = .Site.Params.cdn.jquery_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/jquery/jquery.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $jquery = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/jquery/jquery.min.js" | resources.Minify }}
{{ $jquery = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
<!-- lazysizes https://github.com/aFarkas/lazysizes -->
{{ $lazysizes := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.lazysizes_js }}
{{ $lazysizes = .Site.Params.cdn.lazysizes_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/lazysizes/lazysizes.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $lazysizes = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/lazysizes/lazysizes.min.js" | resources.Minify }}
{{ $lazysizes = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
<!-- KaTeX https://github.com/KaTeX/KaTeX -->
{{ $katex_css := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_css }}
{{ $katex_css = .Site.Params.cdn.katex_css }}
{{ else }}
{{ $secureRes := resources.Get "css/lib/katex/katex.min.css" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $katex_css = printf $secureCSS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "css/lib/katex/katex.min.css" | resources.Minify }}
{{ $katex_css = printf "<link rel=\"stylesheet\" href=\"%s\">" $res.RelPermalink }}
{{ end }}
{{ $katex_js := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_js }}
{{ $katex_js = .Site.Params.cdn.katex_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/katex/katex.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $katex_js = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/katex/katex.min.js" | resources.Minify }}
{{ $katex_js = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
{{ $katex_auto_render_js := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_auto_render_js }}
{{ $katex_auto_render_js = .Site.Params.cdn.katex_auto_render_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/katex/auto-render.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $katex_auto_render_js = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/katex/auto-render.min.js" | resources.Minify }}
{{ $katex_auto_render_js = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
{{ $katex := delimit (slice $katex_css $katex_js $katex_auto_render_js) "" }}
<!-- mermaid https://github.com/knsv/mermaid -->
{{ $diagram := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.mermaid_js }}
{{ $diagram = .Site.Params.cdn.mermaid_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/mermaid/mermaid.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $diagram = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/mermaid/mermaid.min.js" | resources.Minify }}
{{ $diagram = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
{{ $diagram = delimit (slice $diagram "<script>mermaid.initialize({startOnLoad: true, theme: null,});</script>") "" }}
<!-- ECharts https://github.com/apache/incubator-echarts -->
{{ $echarts := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.echarts_js }}
{{ $echarts = .Site.Params.cdn.echarts_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/echarts/echarts.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $echarts = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/echarts/echarts.min.js" | resources.Minify }}
{{ $echarts = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
<!-- TypeIt https://github.com/alexmacarthur/typeit -->
{{ $typeit := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.typeit_js }}
{{ $typeit = .Site.Params.cdn.typeit_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/typeit/typeit.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $typeit = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/typeit/typeit.min.js" | resources.Minify }}
{{ $typeit = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
<!-- jQuery.countdown https://github.com/hilios/jQuery.countdown -->
{{ $countdown := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.jquery_countdown_js }}
{{ $countdown = .Site.Params.cdn.jquery_countdown_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/jquery-countdown/jquery.countdown.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $countdown = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/jquery-countdown/jquery.countdown.min.js" | resources.Minify }}
{{ $countdown = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
<!-- MetingJS https://github.com/metowolf/MetingJS -->
{{ $aplayer_css := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.aplayer_css }}
{{ $aplayer_css = .Site.Params.cdn.aplayer_css }}
{{ else }}
{{ $secureRes := resources.Get "css/lib/aplayer/APlayer.min.css" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $aplayer_css = printf $secureCSS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "css/lib/aplayer/APlayer.min.css" | resources.Minify }}
{{ $aplayer_css = printf "<link rel=\"stylesheet\" href=\"%s\">" $res.RelPermalink }}
{{ end }}
{{ $aplayer_js := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.aplayer_js }}
{{ $aplayer_js = .Site.Params.cdn.aplayer_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/aplayer/APlayer.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $aplayer_js = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/aplayer/APlayer.min.js" | resources.Minify }}
{{ $aplayer_js = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
{{ $meting_js := "" }}
{{ if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.meting_js }}
{{ $meting_js = .Site.Params.cdn.meting_js }}
{{ else }}
{{ $secureRes := resources.Get "js/lib/meting/Meting.min.js" | resources.Minify | resources.Fingerprint "sha512" }}
{{ $meting_js = printf $secureJS $secureRes.RelPermalink $secureRes.Data.Integrity }}
{{ $res := resources.Get "js/lib/meting/Meting.min.js" | resources.Minify }}
{{ $meting_js = printf "<script src=\"%s\"></script>" $res.RelPermalink }}
{{ end }}
{{ $metingjs := delimit (slice $aplayer_css $aplayer_js $meting_js) "" }}

Expand Down Expand Up @@ -139,7 +136,7 @@
<script>var typeitArr = {{ $typeitArr | jsonify | safeJS }};</script>
{{ end }}

{{ $scripts := resources.Get "/js/blog.js" | resources.Minify }}
<script src="{{ $scripts.RelPermalink }}" async=""></script>
{{ $res := resources.Get "/js/blog.js" | resources.Minify }}
<script src="{{ $res.RelPermalink }}"></script>

{{ template "_internal/google_analytics_async.html" . }}

0 comments on commit c8bb077

Please sign in to comment.