site_js.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. {{ $scr := $.Scratch }}
  2. {{/* Attempt to load local vendor JS, otherwise load from CDN. */}}
  3. {{ $js := site.Data.assets.js }}
  4. {{ if not ($scr.Get "use_cdn") }}
  5. <script src="{{ printf "/js/vendor/%s" ($scr.Get "vendor_js_filename") | relURL }}"></script>
  6. {{ else }}
  7. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.jQuery.url $js.jQuery.version) $js.jQuery.sri | safeHTML }}
  8. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.imagesLoaded.url $js.imagesLoaded.version) $js.imagesLoaded.sri | safeHTML }}
  9. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.isotope.url $js.isotope.version) $js.isotope.sri | safeHTML }}
  10. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.fancybox.url $js.fancybox.version) $js.fancybox.sri | safeHTML }}
  11. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.instantpage.url $js.instantpage.version) $js.instantpage.sri | safeHTML }}
  12. {{ if or .Params.diagram site.Params.diagram }}
  13. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" title=\"mermaid\"></script>" (printf $js.mermaid.url $js.mermaid.version) $js.mermaid.sri | safeHTML }}
  14. {{ end }}
  15. {{ if $.Scratch.Get "highlight_enabled" }}
  16. {{ $v := $js.highlight.version }}
  17. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.highlight.url $v) $js.highlight.sri | safeHTML }}
  18. {{ range site.Params.highlight_languages }}
  19. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/{{ $v }}/languages/{{ . }}.min.js"></script>
  20. {{ end }}
  21. {{ end }}
  22. {{ end }}
  23. {{/* Maps JS. */}}
  24. {{ if eq site.Params.map.engine 1 }}
  25. <script async defer src="https://maps.googleapis.com/maps/api/js?key={{ site.Params.map.api_key }}"></script>
  26. {{ if ($scr.Get "use_cdn") }}
  27. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.gmaps.url $js.gmaps.version) $js.gmaps.sri | safeHTML }}
  28. {{ end }}
  29. {{ else if and (or (eq site.Params.map.engine 2) (eq site.Params.map.engine 3)) ($scr.Get "use_cdn") }}
  30. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.leaflet.url $js.leaflet.version) $js.leaflet.sri | safeHTML }}
  31. {{ end }}
  32. {{/* Initialise code highlighting. */}}
  33. {{ if $scr.Get "highlight_enabled" }}
  34. <script>const code_highlighting = true;</script>
  35. {{ else }}
  36. <script>const code_highlighting = false;</script>
  37. {{ end }}
  38. {{ if ne site.Params.search.engine 0 }}
  39. {{/* Configure search engine. */}}
  40. {{ $min_length := site.Params.search.academic.min_length | default 1 }}
  41. {{ $threshold := site.Params.search.academic.threshold | default 0.3 }}
  42. {{ $search_i18n := dict "placeholder" (i18n "search_placeholder") "results" (i18n "search_results") "no_results" (i18n "search_no_results") }}
  43. {{ $search_config := dict "indexURI" ("/index.json" | relLangURL) "threshold" $threshold "minLength" $min_length }}
  44. <script>
  45. const search_config = {{ $search_config | jsonify | safeJS }};
  46. const i18n = {{ $search_i18n | jsonify | safeJS }};
  47. const content_type = {
  48. 'post': {{ i18n "posts" }},
  49. 'project': {{ i18n "projects" }},
  50. 'publication' : {{ i18n "publications" }},
  51. 'talk' : {{ i18n "talks" }},
  52. 'slides' : {{ i18n "slides" | default (i18n "btn_slides") }}
  53. };
  54. </script>
  55. {{ end }}
  56. {{/* Load hash anchors for documentation pages. */}}
  57. {{ if in (slice "book" "docs") .Type }}
  58. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.anchor.url $js.anchor.version) $js.anchor.sri | safeHTML }}
  59. <script>
  60. anchors.add();
  61. </script>
  62. {{ end }}
  63. {{ if eq site.Params.search.engine 1 }}
  64. {{/* Fuse search result template. */}}
  65. <script id="search-hit-fuse-template" type="text/x-template">
  66. <div class="search-hit" id="summary-{{"{{key}}"}}">
  67. <div class="search-hit-content">
  68. <div class="search-hit-name">
  69. {{ printf "<a href=\"%s\">%s</a>" "{{relpermalink}}" "{{title}}" | safeHTML }}
  70. <div class="article-metadata search-hit-type">{{"{{type}}"}}</div>
  71. <p class="search-hit-description">{{"{{snippet}}"}}</p>
  72. </div>
  73. </div>
  74. </div>
  75. </script>
  76. {{ else if eq site.Params.search.engine 2 }}
  77. {{/* Algolia search result template. */}}
  78. <script id="search-hit-algolia-template" type="text/html">
  79. <div class="search-hit">
  80. <div class="search-hit-content">
  81. <div class="search-hit-name">
  82. {{ printf "<a href=\"%s\">{{{_highlightResult.title.value}}}</a>" "{{relpermalink}}" | safeHTML }}
  83. </div>
  84. <div class="article-metadata search-hit-type">{{"{{type}}"}}</div>
  85. <p class="search-hit-description">{{ safeHTML "{{{_highlightResult.summary.value}}}" }}</p>
  86. </div>
  87. </div>
  88. </script>
  89. {{ end }}
  90. {{/* Fuse search engine. */}}
  91. {{ if and (eq site.Params.search.engine 1) ($scr.Get "use_cdn") }}
  92. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.fuse.url $js.fuse.version) $js.fuse.sri | safeHTML }}
  93. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.mark.url $js.mark.version) $js.mark.sri | safeHTML }}
  94. {{ end }}
  95. {{/* Algolia search engine. */}}
  96. {{ if eq site.Params.search.engine 2 }}
  97. {{ if ($scr.Get "use_cdn") }}
  98. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.instantsearch.url $js.instantsearch.version) $js.instantsearch.sri | safeHTML }}
  99. {{ end }}
  100. <script>
  101. const algoliaConfig = {
  102. appId: {{ site.Params.search.algolia.app_id }},
  103. apiKey: {{ site.Params.search.algolia.api_key }},
  104. indexName: {{ site.Params.search.algolia.index_name }},
  105. poweredBy: {{ site.Params.search.algolia.show_logo | default false }}
  106. };
  107. </script>
  108. {{ end }}
  109. {{/* Netlify Identity integration. */}}
  110. {{ if .IsHome | and (site.Params.cms.netlify_cms | default true) }}
  111. <script>
  112. if (window.netlifyIdentity) {
  113. window.netlifyIdentity.on("init", user => {
  114. if (!user) {
  115. window.netlifyIdentity.on("login", () => {
  116. document.location.href = "/admin/";
  117. });
  118. }
  119. });
  120. }
  121. </script>
  122. {{ end }}
  123. {{/* Charts */}}
  124. {{ if .HasShortcode "chart" }}
  125. <script>
  126. window.PlotlyConfig = {MathJaxConfig: 'local'};
  127. </script>
  128. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.plotly.url $js.plotly.version) $js.plotly.sri | safeHTML }}
  129. {{ end }}
  130. {{/* Disqus Comment Count JS. */}}
  131. {{ if and (eq site.Params.comments.engine 1) (site.Params.comments.disqus.show_count | default true) }}
  132. <script id="dsq-count-scr" src="https://{{site.Params.comments.disqus.shortname}}.disqus.com/count.js" async></script>
  133. {{ end }}
  134. {{ $js_comment := printf "/* Wowchemy v%s | https://wowchemy.com/ */\n" site.Data.wowchemy.version }}
  135. {{ $js_bundle_head := $js_comment | resources.FromString "js/bundle-head.js" }}
  136. {{ $js_linebreak := "\n" | resources.FromString "js/linebreak.js" }}{{/* Fix no line break after Bootstrap JS causing error. */}}
  137. {{ $js_academic := resources.Get "js/wowchemy.js" }}
  138. {{ $js_academic_search := resources.Get "js/wowchemy-search.js" }}
  139. {{ $js_algolia_search := resources.Get "js/algolia-search.js" }}
  140. {{ $js_bootstrap := resources.Get "js/_vendor/bootstrap.bundle.js" }}
  141. {{ $js_bundle := slice $js_bootstrap $js_linebreak $js_academic }}
  142. {{ if eq site.Params.search.engine 1 }}
  143. {{ $js_bundle = $js_bundle | append $js_academic_search }}
  144. {{ else if eq site.Params.search.engine 2 }}
  145. {{ $js_bundle = $js_bundle | append $js_algolia_search }}
  146. {{ end }}
  147. {{ range site.Params.plugins_js }}
  148. {{ $js_bundle = $js_bundle | append (resources.Get (printf "js/%s.js" .)) }}
  149. {{ end }}
  150. {{ $js_bundle := $js_bundle | resources.Concat "js/wowchemy-bundle-pre.js" | minify }}
  151. {{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat "js/wowchemy.min.js" | fingerprint "md5" }}
  152. <script src="{{ $js_bundle.RelPermalink }}"></script>
  153. {{ partial "custom_js" . }}