{{- $scratch := .Scratch.Get "scratch" -}}
{{- $CDN := $scratch.Get "CDN" -}}
{{- /* Fork Awesome */ -}}
{{- if $scratch.Get "forkawesome" -}}
{{- slice "lib/forkawesome/fork-awesome.scss" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- /* iconfont */ -}}
{{- if $scratch.Get "iconfont" -}}
{{- slice "lib/iconfont/iconfont.css" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- /* Smooth Scroll */ -}}
{{- with $CDN.smoothScrollJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/smooth-scroll/smooth-scroll.polyfills.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- /* Sharer.js */ -}}
{{- if $scratch.Get "share" -}}
{{- with $CDN.sharerJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/sharer/sharer.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- /* lazysizes */ -}}
{{- with $CDN.lazysizesJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/lazysizes/lazysizes.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- /* lightgallery.js */ -}}
{{- if ne .Site.Params.page.lightgallery false | and (ne .Params.lightgallery false) -}}
{{- with $CDN.lightgalleryCSS -}}
{{- slice . | $scratch.Add "linkCDN" -}}
{{- else -}}
{{- slice "lib/lightgallery/lightgallery.min.css" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- with $CDN.lightgalleryJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/lightgallery/lightgallery.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- with $CDN.lightgalleryThumbnailJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/lightgallery/lg-thumbnail.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- with $CDN.lightgalleryZoomJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/lightgallery/lg-zoom.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- /* TypeIt */ -}}
{{- with $scratch.Get "typeitMap" -}}
{{- with $CDN.typeitJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/typeit/typeit.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- range $key, $val := . -}}
{{- slice $val | $scratch.Add "typeitArr" -}}
{{- end -}}
{{- end -}}
{{- /* KaTeX */ -}}
{{- if ne .Site.Params.math.enable false | and .Params.math -}}
{{- with $CDN.katexCSS -}}
{{- slice . | $scratch.Add "linkCDN" -}}
{{- else -}}
{{- slice "lib/katex/katex.min.css" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- with $CDN.katexJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/katex/katex.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- with $CDN.katexAutoRenderJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "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 "lib/katex/copy-tex.min.css" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- with $CDN.katexCopyTexJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/katex/copy-tex.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- if $math.mhchem -}}
{{- with $CDN.katexMhchemJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/katex/mhchem.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* mermaid */ -}}
{{- with $scratch.Get "mermaidArr" -}}
{{- with $CDN.mermaidJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/mermaid/mermaid.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- slice "lib/mermaid/mermaid.scss" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- /* ECharts */ -}}
{{- with $scratch.Get "echartsArr" -}}
{{- with $CDN.echartsJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/echarts/echarts.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- with $CDN.echartsMacaronsJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/echarts/macarons.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- /* Music */ -}}
{{- if $scratch.Get "music" -}}
{{- /* APlayer */ -}}
{{- with $CDN.aplayerCSS -}}
{{- slice . | $scratch.Add "linkCDN" -}}
{{- else -}}
{{- slice "lib/aplayer/APlayer.min.css" | $scratch.Add "linkLocal" -}}
{{- end -}}
{{- slice "lib/aplayer/dark.scss" | $scratch.Add "linkLocal" -}}
{{- with $CDN.aplayerJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/aplayer/APlayer.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- /* MetingJS */ -}}
{{- with $CDN.metingJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
{{- slice "lib/meting/Meting.min.js" | $scratch.Add "scriptLocal" -}}
{{- end -}}
{{- end -}}
{{- /* Dev feature */ -}}
{{- if .Params.dev -}}
{{- end -}}
{{- with $scratch.Get "contentMap" -}}
{{- end -}}
{{- /* Theme script */ -}}
{{- slice "js/theme.min.js" | $scratch.Add "scriptLocal" -}}
{{- $_ := (resources.Get "js/theme.min.js.map").RelPermalink -}}
{{- 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 -}}
{{- $stylesheet := dict "resource" $res "fingerprint" ($scratch.Get "fingerprint") -}}
{{- partial "plugin/stylesheet.html" $stylesheet -}}
{{- 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 := dict "resource" $res "fingerprint" ($scratch.Get "fingerprint") -}}
{{- partial "plugin/script.html" $script -}}
{{- end -}}
{{- /* Google analytics async */ -}}
{{- if $scratch.Get "production" | and .Site.GoogleAnalytics -}}
{{- template "_internal/google_analytics_async.html" . -}}
{{- end -}}