{{ define "main" }}

<header>
    <img id="banner" />
    {{- if $.Site.Params.theme_config.show_description -}}
        <p>{{ $.Site.Params.description }}</p>
    {{- end -}}
</header>

{{ if hugo.IsProduction }}
<!-- prod implementation -->
<script>
  fetch("/banners/")
    .then((response) => response.text())
    .then((html) => {
      const parser = new DOMParser()
      const doc = parser.parseFromString(html, "text/html")
      const links = Array.from(doc.querySelectorAll('a[href$=".png"]'))

      if (links.length > 0) {
        const randomIdx = Math.floor(Math.random() * links.length)
        const bannerPath = "/banners/" + links[randomIdx].getAttribute("href")
        document.getElementById("banner").src = bannerPath
      }
    })
</script>
{{ else }}
<!-- dev fallback -->
<script>
  document.getElementById("banner").src = "/images/banner-placeholder.png"
</script>
{{ end }}

{{ .Content }}
{{ partial "menu_item.html" (dict "context" . "collection" $.Site.Data.menu.entries) }}

{{ end }}