LoveIt/layouts/partials/script.html
Dillon 315eb094e5 Squashed commit of the following:
commit 6430e78c16
Merge: 5855527 b13bbc3
Author: Dillon <dillonzq@outlook.com>
Date:   Wed Feb 19 19:31:28 2020 +0800

    Merge pull request #84 from dillonzq/fix/duplicated_typeit

    fix(typeit): fix duplicated typeit bug (#82)

commit b13bbc368c
Author: Dillon <dillonzq@outlook.com>
Date:   Wed Feb 19 19:25:49 2020 +0800

    fix(typeit): fix duplicated typeit bug (#82)

commit 58555274f5
Merge: 16320fa 02919a7
Author: Dillon <dillonzq@outlook.com>
Date:   Wed Feb 19 18:59:21 2020 +0800

    Merge pull request #83 from dillonzq/fix/social_link_href

    fix(social): fix social link bug (#81)

commit 02919a7d48
Author: Dillon <dillonzq@outlook.com>
Date:   Wed Feb 19 18:55:40 2020 +0800

    fix(social): fix social link bug (#81)
2020-02-20 11:55:52 +08:00

201 lines
7.4 KiB
HTML

{{- $CDN := .Scratch.Get "CDN" -}}
{{- $localScratch := newScratch -}}
{{- /* Fork Awesome https://forkaweso.me/ */ -}}
{{- if .Scratch.Get "forkawesome" -}}
{{- slice "css/lib/forkawesome/fork-awesome.scss" | .Scratch.Add "linkLocal" -}}
{{- end -}}
{{- /* iconfont https://www.iconfont.cn/ */ -}}
{{- if .Scratch.Get "iconfont" -}}
{{- slice "css/lib/iconfont/iconfont.css" | .Scratch.Add "linkLocal" -}}
{{- end -}}
{{- /* Smooth Scroll https://github.com/cferdinandi/smooth-scroll */ -}}
{{- with $CDN.smoothScrollJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/smooth-scroll/smooth-scroll.polyfills.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- /* Sharer.js https://github.com/ellisonleao/sharer.js */ -}}
{{- if .Scratch.Get "share" -}}
{{- with $CDN.sharerJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/sharer/sharer.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- /* lazysizes https://github.com/aFarkas/lazysizes */ -}}
{{- with $CDN.lazysizesJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/lazysizes/lazysizes.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- /* TypeIt https://github.com/alexmacarthur/typeit */ -}}
{{- with .Scratch.Get "typeitMap" -}}
{{- with $CDN.typeitJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/typeit/typeit.min.js" | $.Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- range $key, $val := . -}}
{{- slice $val | $localScratch.Add "typeitArr" -}}
{{- end -}}
<script>
window.typeitArr = {{ $localScratch.Get "typeitArr" | jsonify | safeJS }};
</script>
{{- end -}}
{{- /* KaTeX https://github.com/KaTeX/KaTeX */ -}}
{{- if .Site.Params.math.enable | and (ne .Params.math false) -}}
{{- with $CDN.katexCSS -}}
{{- slice . | $.Scratch.Add "linkCDN" -}}
{{- else -}}
{{- slice "css/lib/katex/katex.min.css" | .Scratch.Add "linkLocal" -}}
{{- end -}}
{{- with $CDN.katexJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/katex/katex.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- with $CDN.katexAutoRenderJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/katex/auto-render.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- $math := .Site.Params.math -}}
{{- if $math.copyTex -}}
{{- with $CDN.katexCopyTexCSS -}}
{{- slice . | $.Scratch.Add "linkCDN" -}}
{{- else -}}
{{- slice "css/lib/katex/copy-tex.min.css" | .Scratch.Add "linkLocal" -}}
{{- end -}}
{{- with $CDN.katexCopyTexJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/katex/copy-tex.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- if $math.mhchem -}}
{{- with $CDN.katexMhchemJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/katex/mhchem.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
<script>
document.addEventListener("DOMContentLoaded", function () {
renderMathInElement(document.body, {
delimiters: [
{ left: "$", right: "$", display: false },
{ left: "$$", right: "$$", display: true },
{ left: "\\(", right: "\\)", display: false },
{ left: "\\[", right: "\\]", display: true },
{{- if and $math.inlineLeftDelimiter $math.inlineRightDelimiter -}}
{ left: "{{ $math.inlineLeftDelimiter }}", right: "{{ $math.inlineRightDelimiter }}", display: false },
{{- end -}}
{{- if and $math.blockLeftDelimiter $math.blockRightDelimiter -}}
{ left: "{{ $math.blockLeftDelimiter }}", right: "{{ $math.blockRightDelimiter }}", display: true },
{{- end -}}
]
});
});
</script>
{{- end -}}
{{- /* mermaid https://github.com/knsv/mermaid */ -}}
{{- with .Scratch.Get "mermaidMap" -}}
{{- with $CDN.mermaidJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/mermaid/mermaid.min.js" | $.Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- slice "css/mermaid.scss" | $.Scratch.Add "linkLocal" -}}
<script>
window.mermaidMap = {{ jsonify . | safeJS }};
</script>
{{- end -}}
{{- /* Music */ -}}
{{- if .Scratch.Get "music" -}}
{{- /* APlayer https://github.com/MoePlayer/APlayer */ -}}
{{- with $CDN.aplayerCSS -}}
{{- slice . | $.Scratch.Add "linkCDN" -}}
{{- else -}}
{{- slice "css/lib/aplayer/APlayer.min.css" | .Scratch.Add "linkLocal" -}}
{{- end -}}
{{- slice "css/lib/aplayer/dark.scss" | .Scratch.Add "linkLocal" -}}
{{- with $CDN.aplayerJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/aplayer/APlayer.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- /* MetingJS https://github.com/metowolf/MetingJS */ -}}
{{- with $CDN.metingJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/meting/Meting.min.js" | .Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- /* dev feature */ -}}
{{- if .Params.dev -}}
{{- /* ECharts https://github.com/apache/incubator-echarts */ -}}
{{- with .Scratch.Get "echartsMap" -}}
{{- with $CDN.echartsJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/echarts/echarts.min.js" | $.Scratch.Add "scriptLocal" -}}
{{- end -}}
{{- with $CDN.echartsMacaronsJS -}}
{{- slice . | $.Scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "js/lib/echarts/macarons.js" | $.Scratch.Add "scriptLocal" -}}
{{- end -}}
<script>
window.echartsMap = {
{{- range $key, $var := . -}}
{{- $key }}: {{ $var | safeJS -}},
{{- end -}}
};
window.echartsArr = [];
</script>
{{- end -}}
{{- end -}}
{{- range .Scratch.Get "linkCDN" -}}
{{- safeHTML . -}}
{{- end -}}
{{- range .Scratch.Get "linkLocal" -}}
{{- $res := resources.Get . -}}
{{- if strings.HasSuffix . ".scss" -}}
{{- $options := dict "outputStyle" "compressed" "enableSourceMap" true -}}
{{- $res = toCSS $options $res -}}
{{- else if not (strings.HasSuffix . ".min.css") -}}
{{- $res = minify $res -}}
{{- end -}}
<link rel="stylesheet" href="{{ $res.RelPermalink }}">
{{- end -}}
{{- range .Scratch.Get "scriptCDN" -}}
{{- safeHTML . -}}
{{- end -}}
{{- range .Scratch.Get "scriptLocal" -}}
{{- $res := resources.Get . -}}
{{- if not (strings.HasSuffix . ".min.js") -}}
{{- $res = minify $res -}}
{{- end -}}
<script src="{{ $res.RelPermalink }}"></script>
{{- end -}}
{{- /* Theme script */ -}}
<script src=/js/theme.min.js></script>
{{- /* Google analytics async */ -}}
{{- if .Scratch.Get "production" | and .Site.GoogleAnalytics -}}
{{- template "_internal/google_analytics_async.html" . -}}
{{- end -}}