<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode | default "en" }}">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    
    {{/* Generate consistent title */}}
    {{ $title := "" }}
    {{ if .Params.narrator }}
      {{ $title = printf "%s: %s" .Params.narrator .Params.subject }}
    {{ else if .IsHome }}
      {{ $title = .Title }}
    {{ else }}
      {{ $title = printf "%s - %s" .Title .Site.Title }}
    {{ end }}
    
    <!-- Basic SEO -->
    <title>{{ $title }}{{ if .Params.narrator }} - {{ .Site.Title }}{{ end }}</title>
    
    {{/* Generate description from summary, description, or default site description */}}
    {{ $description := "" }}
    {{ with .Description }}
      {{ $description = . }}
    {{ else }}
      {{ with .Summary }}
        {{ $description = . | plainify | truncate 160 }}
      {{ else }}
        {{ $description = .Site.Params.description }}
      {{ end }}
    {{ end }}
    <meta name="description" content="{{ $description }}" />
    
    {{/* Generate keywords from topics */}}
    {{ with .Params.topics }}
    <meta name="keywords" content="{{ delimit . ", " }}" />
    {{ end }}
    
    <!-- Open Graph / Facebook -->
    <meta property="og:site_name" content="{{ .Site.Title }}" />
    <meta property="og:type" content="{{ if .IsPage }}interview{{ else }}website{{ end }}" />
    <meta property="og:url" content="{{ .Permalink }}" />
    <meta property="og:title" content="{{ $title }}" />
    <meta property="og:description" content="{{ $description }}" />
    {{ with .Params.ogImage | default .Site.Params.openGraphImage }}
    <meta property="og:image" content="{{ . | absURL }}" />
    {{ end }}
    
    <!-- Twitter -->
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:title" content="{{ $title }}" />
    <meta name="twitter:description" content="{{ $description }}" />
    {{ with .Params.ogImage | default .Site.Params.openGraphImage }}
    <meta name="twitter:image" content="{{ . | absURL }}" />
    {{ end }}
    
    <!-- Interview Specific -->
    {{ if and .IsPage (eq .Type "interviews") }}
      <meta property="interview:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}" />
      <meta property="interview:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}" />
      <meta property="interview:section" content="Oral History" />
      {{ with .Params.topics }}
        {{ range . }}
        <meta property="interview:tag" content="{{ . }}" />
        {{ end }}
      {{ end }}
      
      {{/* Author information using standard meta topics instead of interview:author */}}
      {{ with .Params.narrator }}
      <meta name="author" content="{{ . }}" />
      {{ end }}
      {{ with .Params.facilitator }}
      <meta name="interviewer" content="{{ . }}" />
      {{ end }}
    {{ end }}
    
    <!-- Canonical URL -->
    <link rel="canonical" href="{{ .Permalink }}" />
    
    <!-- CSS Styles -->
    {{ partial "css.html" . }}


    <!-- Matomo -->
    <script>
      var _paq = window._paq = window._paq || [];
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      (function() {
        var u="https://analytics.medlab.host/";
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', '8']);
        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 -->

  </head>
  <body class="">
    {{ partial "header.html" . }}
    <div class="px-4 lg:mx-auto">
      {{ block "main" . }}{{ end }}
    </div>
    {{ partial "footer.html" . }}
    
    {{ $js := resources.Match "js/*.js" | resources.Concat "js/bundle.js" }}
    {{ if hugo.IsProduction }}
      {{ $js = $js | minify | fingerprint }}
      <script src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous"></script>
    {{ else }}
      <script src="{{ $js.RelPermalink }}"></script>
    {{ end }}
  </body>
</html>
