{{ $isDocsPage := eq .Section "docs" }}
{{ $app        := resources.Get "js/app.js" | resources.ExecuteAsTemplate "js/app.js" . | fingerprint }}
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"
        onerror="console.error('Error loading the docsearch.min.js script')"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
        integrity="sha512-+NqPlbbtM1QqiK8ZAo4Yrj2c4lNQoGv8P79DPtKzj++l5jnN39rHA/xsqn8zE9l0uSoxaCdrOgFs6yjyfbBxSg=="
        crossorigin="anonymous"
        referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.7.0/tocbot.min.js"
        integrity="sha512-0yvqkr9Ldt1VsW3izBRlvZuz0Sd1Yu+ZRZSFg33ogi0FJi7FlzP3s1QOrA0Fd0XbAEXMdSrLQBlCFyHq4kNEEQ=="
        crossorigin="anonymous"
        referrerpolicy="no-referrer"></script>
<script src="{{ $app.RelPermalink }}" integrity="{{ $app.Data.Integrity }}"></script>
<script src="/js/anchor.min.js"></script>

{{ if $isDocsPage }}
{{ $version := index (split .File.Path "/") 1 }}
{{ $apiKey  := site.Params.algolia_api_key }}
<script>
  console.log("You are reading the docs for version {{ $version }} of Open Policy Agent");
    docsearch({
      container: '#docsearch',
      appId: 'P4N61UNFMP',
      indexName: 'openpolicyagent',
      apiKey: '{{ $apiKey }}',
      searchParameters: { 'facetFilters': ["version:{{ $version }}"] }
    });
</script>
{{ end }}