{{- $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 -}}
{{- 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 -}}
{{- 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" -}}
{{- 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 -}}
{{- 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 -}}
{{- end -}}
{{- range .Scratch.Get "scriptCDN" -}}
{{- safeHTML . -}}
{{- end -}}
{{- range .Scratch.Get "scriptLocal" -}}
{{- $res := resources.Get . -}}
{{- if not (strings.HasSuffix . ".min.js") -}}
{{- $res = minify $res -}}
{{- end -}}
{{- end -}}
{{- /* Theme script */ -}}
{{- /* Google analytics async */ -}}
{{- if .Scratch.Get "production" | and .Site.GoogleAnalytics -}}
{{- template "_internal/google_analytics_async.html" . -}}
{{- end -}}