{{ $scr := $.Scratch }}
{{/* Attempt to load local vendor JS, otherwise load from CDN. */}}
{{ $js := site.Data.assets.js }}
{{ if not ($scr.Get "use_cdn") }}
{{ else }}
{{ printf "" (printf $js.jQuery.url $js.jQuery.version) $js.jQuery.sri | safeHTML }}
{{ printf "" (printf $js.imagesLoaded.url $js.imagesLoaded.version) $js.imagesLoaded.sri | safeHTML }}
{{ printf "" (printf $js.isotope.url $js.isotope.version) $js.isotope.sri | safeHTML }}
{{ printf "" (printf $js.fancybox.url $js.fancybox.version) $js.fancybox.sri | safeHTML }}
{{ if or .Params.diagram site.Params.diagram }}
{{ printf "" (printf $js.mermaid.url $js.mermaid.version) $js.mermaid.sri | safeHTML }}
{{ end }}
{{ if $.Scratch.Get "highlight_enabled" }}
{{ $v := $js.highlight.version }}
{{ printf "" (printf $js.highlight.url $v) $js.highlight.sri | safeHTML }}
{{ range site.Params.highlight_languages }}
{{ end }}
{{ end }}
{{ end }}
{{/* Maps JS. */}}
{{ if eq site.Params.map.engine 1 }}
{{ if ($scr.Get "use_cdn") }}
{{ printf "" (printf $js.gmaps.url $js.gmaps.version) $js.gmaps.sri | safeHTML }}
{{ end }}
{{ else if and (or (eq site.Params.map.engine 2) (eq site.Params.map.engine 3)) ($scr.Get "use_cdn") }}
{{ printf "" (printf $js.leaflet.url $js.leaflet.version) $js.leaflet.sri | safeHTML }}
{{ end }}
{{/* Initialise code highlighting. */}}
{{ if $scr.Get "highlight_enabled" }}
{{ else }}
{{ end }}
{{/* Initialise default theme. */}}
{{ if eq ($scr.Get "light") true }}
{{ else }}
{{ end }}
{{ if ne site.Params.search.engine 0 }}
{{/* Configure search engine. */}}
{{ $min_length := site.Params.search.academic.min_length | default 1 }}
{{ $threshold := site.Params.search.academic.threshold | default 0.3 }}
{{ $search_i18n := dict "placeholder" (i18n "search_placeholder") "results" (i18n "search_results") "no_results" (i18n "search_no_results") }}
{{ $search_config := dict "indexURI" ("/index.json" | relLangURL) "threshold" $threshold "minLength" $min_length }}
{{ end }}
{{/* Load hash anchors for documentation pages. */}}
{{ if eq .Type "docs" }}
{{ printf "" (printf $js.anchor.url $js.anchor.version) $js.anchor.sri | safeHTML }}
{{ end }}
{{ if eq site.Params.search.engine 1 }}
{{/* Fuse search result template. */}}
{{ else if eq site.Params.search.engine 2 }}
{{/* Algolia search result template. */}}
{{ end }}
{{/* Fuse search engine. */}}
{{ if and (eq site.Params.search.engine 1) ($scr.Get "use_cdn") }}
{{ printf "" (printf $js.fuse.url $js.fuse.version) $js.fuse.sri | safeHTML }}
{{ printf "" (printf $js.mark.url $js.mark.version) $js.mark.sri | safeHTML }}
{{ end }}
{{/* Algolia search engine. */}}
{{ if eq site.Params.search.engine 2 }}
{{ if ($scr.Get "use_cdn") }}
{{ printf "" (printf $js.instantsearch.url $js.instantsearch.version) $js.instantsearch.sri | safeHTML }}
{{ end }}
{{ end }}
{{/* Netlify Identity integration. */}}
{{ if .IsHome | and (site.Params.cms.netlify_cms | default true) }}
{{ end }}
{{/* Disqus Comment Count JS. */}}
{{ if and (eq site.Params.comments.engine 1) (site.Params.comments.disqus.show_count | default true) }}
{{ end }}
{{ $js_comment := printf "/* Source Themes Academic v%s | https://sourcethemes.com/academic/ */\n" site.Data.academic.version }}
{{ $js_bundle_head := $js_comment | resources.FromString "js/bundle-head.js" }}
{{ $js_linebreak := "\n" | resources.FromString "js/linebreak.js" }}{{/* Fix no line break after Bootstrap JS causing error. */}}
{{ $js_academic := resources.Get "js/academic.js" }}
{{ $js_academic_search := resources.Get "js/academic-search.js" }}
{{ $js_algolia_search := resources.Get "js/algolia-search.js" }}
{{ $js_bootstrap := resources.Get "js/vendor/bootstrap.min.js" }}
{{ $js_bundle := slice $js_bootstrap $js_linebreak $js_academic }}
{{ if eq site.Params.search.engine 1 }}
{{ $js_bundle = $js_bundle | append $js_academic_search }}
{{ else if eq site.Params.search.engine 2 }}
{{ $js_bundle = $js_bundle | append $js_algolia_search }}
{{ end }}
{{ range site.Params.plugins_js }}
{{ $js_bundle = $js_bundle | append (resources.Get (printf "js/%s.js" .)) }}
{{ end }}
{{ $js_bundle := $js_bundle | resources.Concat "js/academic-bundle-pre.js" | minify }}
{{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat "js/academic.min.js" | fingerprint "md5" }}
{{ partial "custom_js" . }}