{{/* cSpell:ignore docsearch opengraph outputformat */ -}}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

{{ $darkMode := partialCached "dark-mode-config.html" "dark-mode-global" -}}
{{ if $darkMode.enable -}}
{{/* Browser hints before CSS loads */ -}}
<meta name="color-scheme" content="light dark">
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#ffffff">
<meta name="theme-color" media="(prefers-color-scheme: dark)"  content="#000000">

{{/* Styles to set canvas colors and avoid transitions */ -}}
<style>
  {{/* Set system colors as default */ -}}
  html { background: Canvas; color: CanvasText; }
  {{/* Define reasonable dark defaults */ -}}
  @media (prefers-color-scheme: dark) {
    html { background: #0b0d12; color: #e6e6e6; }
  }
  {{/* Avoid transitions until theme CSS is loaded */ -}}
  html[data-theme-init] * { transition: none !important; }
</style>

{{/* Set theme attribute before CSS loads to prevent flash */ -}}
<script>
  (function() {
    const themeKey = 'td-color-theme';
    const storedTheme = localStorage.getItem(themeKey);
    let theme = storedTheme || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');

    if (theme === 'auto') {
      theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    }

    document.documentElement.setAttribute('data-bs-theme', theme);
  })();
</script>
{{ end -}}

{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
{{ end -}}

{{ $outputFormat := partial "outputformat.html" . -}}
{{ if and hugo.IsProduction (ne $outputFormat "print") (ne .Site.Language.Lang "xx") -}}
<meta name="robots" content="index, follow">
{{ else -}}
<meta name="robots" content="noindex, nofollow">
{{ end -}}

{{ partialCached "favicons.html" . }}
<title>
  {{- if .IsHome -}}
    {{ .Site.Title -}}
  {{ else -}}
    {{ with .Title }}{{ . }} | {{ end -}}
    {{ .Site.Title -}}
  {{ end -}}
</title>
<meta name="description" content="{{ partial "page-description.html" . }}">
{{ partial "opengraph.html" . -}}
{{ partial "schema.html" . -}}
{{ partial "twitter_cards.html" . -}}
{{ partialCached "head-css.html" . "head-css-cache-key" -}}

<!--
Customization to host jQuery + Lunr JS files on ASF site
-->
{{ $jqueryUrl := "https://code.jquery.com/jquery-3.7.1.min.js" -}}
{{ with resources.GetRemote $jqueryUrl }}
<script
  src="{{ .RelPermalink }}"
  integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
  crossorigin="anonymous"></script>
{{ end -}}
{{ if .Site.Params.offlineSearch -}}
{{ $lunrUrl := "https://unpkg.com/lunr@2.3.9/lunr.min.js" -}}
{{ with resources.GetRemote $lunrUrl }}
<script defer
  src="{{ .RelPermalink }}"
  integrity="sha384-203J0SNzyqHby3iU6hzvzltrWi/M41wOP5Gu+BiJMz5nwKykbkUx8Kp7iti0Lpli"
  crossorigin="anonymous"></script>
{{ end -}}
{{ end -}}

{{ if .Site.Params.prism_syntax_highlighting -}}
<link rel="stylesheet" href="{{ "css/prism.css" | relURL }}"/>
{{ end -}}

{{ template "algolia/head" . -}}

{{ partial "hooks/head-end.html" . -}}

<!--
Google Analytics part removed.
-->

{{ define "algolia/head" -}}

{{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3.8.2"
  integrity="sha512-l7pkV1dOURFyHCeH8I4fK9lCkQKuqhlsTCqRl3zktifDlB8oTUJ+mJPgYkK9kHpUut8j1iPquTv32t6hvTPv3g=="
  crossorigin="anonymous" />
{{ end -}}

{{ if ne .Site.Params.algolia_docsearch nil -}}
{{ warnf `Config 'params.algolia_docsearch' is deprecated: use 'params.search.algolia'
      For details, see https://www.docsy.dev/docs/content/search/#algolia-docsearch.` -}}
{{ end -}}

{{ end -}}

<!-- Matomo -->
<script>
  /* Analytics for https://polaris.apache.org/ */
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before
"trackPageView" */
  _paq.push(["setDoNotTrack", true]);
  _paq.push(["disableCookies"]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="https://analytics.apache.org/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '81']);
    var d=document, g=d.createElement('script'),
            s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->
