fix(scripts): fix CDN not work bug

This commit is contained in:
Dillon 2020-02-07 21:42:47 +08:00
parent 61250a0ae4
commit a20700595d

View file

@ -35,17 +35,17 @@
{{- $smooth_scroll | safeHTML -}} {{- $smooth_scroll | safeHTML -}}
{{- /* TypeIt https://github.com/alexmacarthur/typeit */ -}} {{- /* TypeIt https://github.com/alexmacarthur/typeit */ -}}
{{- with .Scratch.Get "typeitMap" -}} {{- if .Scratch.Get "typeitMap" -}}
{{- $typeit := "" -}} {{- $typeit := "" -}}
{{- if eq (getenv "HUGO_ENV") "production" | and $.Site.Params.cdn.typeit_js -}} {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.typeit_js -}}
{{- $typeit = $.Site.Params.cdn.typeit_js -}} {{- $typeit = .Site.Params.cdn.typeit_js -}}
{{- else -}} {{- else -}}
{{- $res := resources.Get "js/lib/typeit/typeit.min.js" -}} {{- $res := resources.Get "js/lib/typeit/typeit.min.js" -}}
{{- $typeit = printf "<script src=\"%s\"></script>" $res.RelPermalink -}} {{- $typeit = printf "<script src=\"%s\"></script>" $res.RelPermalink -}}
{{- end -}} {{- end -}}
{{- $typeit | safeHTML -}} {{- $typeit | safeHTML -}}
{{- $typeitArr := slice -}} {{- $typeitArr := slice -}}
{{- range $key, $val := . -}} {{- range $key, $val := .Scratch.Get "typeitMap" -}}
{{- $typeitArr = $typeitArr | append (slice $val) -}} {{- $typeitArr = $typeitArr | append (slice $val) -}}
{{- end -}} {{- end -}}
<script> <script>
@ -126,7 +126,7 @@
{{- end -}} {{- end -}}
{{- /* mermaid https://github.com/knsv/mermaid */ -}} {{- /* mermaid https://github.com/knsv/mermaid */ -}}
{{- with .Scratch.Get "mermaidMap" -}} {{- if .Scratch.Get "mermaidMap" -}}
{{- $mermaid := "" -}} {{- $mermaid := "" -}}
{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.mermaid_js -}} {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.mermaid_js -}}
{{- $mermaid = .Site.Params.cdn.mermaid_js -}} {{- $mermaid = .Site.Params.cdn.mermaid_js -}}
@ -138,7 +138,7 @@
{{- $mermaid = delimit (slice $mermaid $mermaidInit) "" -}} {{- $mermaid = delimit (slice $mermaid $mermaidInit) "" -}}
{{- $mermaid | safeHTML -}} {{- $mermaid | safeHTML -}}
<script> <script>
{{- printf "window.mermaidMap=%s;" (jsonify .) | safeJS -}} {{- printf "window.mermaidMap=%s;" (jsonify .Scratch.Get "mermaidMap") | safeJS -}}
</script> </script>
{{- end -}} {{- end -}}
@ -174,7 +174,7 @@
{{- end -}} {{- end -}}
{{- /* jQuery.countdown https://github.com/hilios/jQuery.countdown */ -}} {{- /* jQuery.countdown https://github.com/hilios/jQuery.countdown */ -}}
{{- with .Scratch.Get "countdownMap" -}} {{- if .Scratch.Get "countdownMap" -}}
{{- $countdown := "" -}} {{- $countdown := "" -}}
{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.jquery_countdown_js -}} {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.jquery_countdown_js -}}
{{- $countdown = .Site.Params.cdn.jquery_countdown_js -}} {{- $countdown = .Site.Params.cdn.jquery_countdown_js -}}
@ -184,14 +184,14 @@
{{- end -}} {{- end -}}
{{- $countdown | safeHTML -}} {{- $countdown | safeHTML -}}
<script> <script>
{{- printf "window.countdownMap=%s;" (jsonify .) | safeJS -}} {{- printf "window.countdownMap=%s;" (jsonify .Scratch.Get "countdownMap") | safeJS -}}
</script> </script>
{{- end -}} {{- end -}}
{{- /* dev feature */ -}} {{- /* dev feature */ -}}
{{- if .Params.dev -}} {{- if .Params.dev -}}
{{- /* ECharts https://github.com/apache/incubator-echarts */ -}} {{- /* ECharts https://github.com/apache/incubator-echarts */ -}}
{{- with .Scratch.Get "echartsMap" -}} {{- if .Scratch.Get "echartsMap" -}}
{{- $echarts_js := "" -}} {{- $echarts_js := "" -}}
{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.echarts_js -}} {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.echarts_js -}}
{{- $echarts_js = .Site.Params.cdn.echarts_js -}} {{- $echarts_js = .Site.Params.cdn.echarts_js -}}
@ -210,7 +210,7 @@
{{- $echarts | safeHTML -}} {{- $echarts | safeHTML -}}
<script> <script>
window.echartsMap = { window.echartsMap = {
{{- range $key, $var := . -}} {{- range $key, $var := .Scratch.Get "echartsMap" -}}
{{- $key }}: {{ $var | safeJS -}}, {{- $key }}: {{ $var | safeJS -}},
{{- end -}} {{- end -}}
}; };