Commit 335e3d33 authored by Thomas Bouffard's avatar Thomas Bouffard
Browse files

chore: only load docsearch resources when search is displayed

This avoids loading useless resources when the search is not available in the
page. It previously generated a JS error because some HTML element was not
present in the page.

Also use specific version of docsearch resources to improve caching and use SRI.
parent e5a04b04
<script async src="{{{uiRootPath}}}/js/vendor/asciinema-player.min.js"></script> <script async src="{{{uiRootPath}}}/js/vendor/asciinema-player.min.js"></script>
<script src="{{{uiRootPath}}}/js/vendor/highlight.min.js"></script> <script src="{{{uiRootPath}}}/js/vendor/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script> {{!-- DocSearch only available if the search bar is displayed --}}
{{#unless site.keys.nonProduction}}
{{#unless page.attributes.hide-search-bar }}
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2.6.3/dist/cdn/docsearch.min.js" integrity="sha256-qybEsgf0PGiQS22AmoozPs09oRnSC7Gu7eBu4fbS2Ac=" crossorigin="anonymous"></script>
{{/unless}}
{{/unless}}
<script>hljs.initHighlightingOnLoad();</script> <script>hljs.initHighlightingOnLoad();</script>
<script src="{{{uiRootPath}}}/js/site.js"></script> <script src="{{{uiRootPath}}}/js/site.js"></script>
{{!-- DocSearch only available if the search bar is displayed --}}
{{#unless site.keys.nonProduction}}
{{#unless page.attributes.hide-search-bar }}
<script> <script>
var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@1.7.1"; var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@1.7.1";
...@@ -43,6 +51,8 @@ ...@@ -43,6 +51,8 @@
apiKey: '16267f96d135c47df8454efd5b448c9a', apiKey: '16267f96d135c47df8454efd5b448c9a',
}); });
</script> </script>
{{/unless}}
{{/unless}}
<script> <script>
// init toggle state // init toggle state
......
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" /> {{!-- DocSearch only available if the search bar is displayed --}}
{{#unless site.keys.nonProduction}}
{{#unless page.attributes.hide-search-bar }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2.6.3/dist/cdn/docsearch.css" integrity="sha256-tY3FCmL2d8yoJBOVyC2aOxdixg8sLT6CHlDWX/VUJaY=" crossorigin="anonymous">
{{/unless}}
{{/unless}}
<link rel="stylesheet" href="{{{uiRootPath}}}/stylesheets/vendor/asciinema-player.css"> <link rel="stylesheet" href="{{{uiRootPath}}}/stylesheets/vendor/asciinema-player.css">
<link rel="stylesheet" href="{{{uiRootPath}}}/stylesheets/site.css"> <link rel="stylesheet" href="{{{uiRootPath}}}/stylesheets/site.css">
<link id="highlight-style-lnk" rel="stylesheet" href="{{{uiRootPath}}}/stylesheets/vendor/highlight-light.css"> <link id="highlight-style-lnk" rel="stylesheet" href="{{{uiRootPath}}}/stylesheets/vendor/highlight-light.css">
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment