{{ $scr := $.Scratch }}
{{/* Config LaTeX math rendering. */}}
{{ if or .Params.math site.Params.math }}
{{ $mathjax_config := resources.Get "js/mathjax-config.js" }}
{{ end }}
{{/* 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 }}
{{/* LaTeX math rendering. */}}
{{ if or .Params.math site.Params.math }}
{{ printf "" (printf $js.mathJax.url $js.mathJax.version) $js.mathJax.sri | safeHTML }}
{{ end }}
{{ end }}
{{/* Maps JS. */}}
{{ if eq site.Params.map 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 2) (eq site.Params.map 3)) ($scr.Get "use_cdn") }}
{{ printf "" (printf $js.leaflet.url $js.leaflet.version) $js.leaflet.sri | safeHTML }}
{{ end }}
{{/* Comments JS. */}}
{{ $comments_enabled := and site.DisqusShortname (not (or site.Params.disable_comments $.Params.disable_comments)) }}
{{ if and $comments_enabled (site.Params.comment_count | default true) }}
{{ end }}
{{/* Initialise code highlighting. */}}
{{ if $.Scratch.Get "highlight_enabled" }}
{{ end }}
{{ if ne site.Params.search.engine 0 }}
{{/* Configure search engine. */}}
{{ 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 }}
{{ $js_comment := printf "/* Source Themes academia v%s | https://sourcethemes.com/academic/ */\n" site.Data.academia.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_academia := resources.Get "js/academia.js" }}
{{ $js_academia_search := resources.Get "js/academia-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_academia }}
{{ if eq site.Params.search.engine 1 }}
{{ $js_bundle = $js_bundle | append $js_academia_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/academia-bundle-pre.js" | minify }}
{{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat "js/academia.min.js" | fingerprint "md5" }}
{{ partial "custom_js" . }}