{{ $version := "latest" }}
{{ if strings.HasPrefix .RelPermalink "/docs/" }}
  {{ $version = index (split .File.Path "/") 1 -}}
{{ end -}}
{{ $isHome      := .IsHome }}
{{ $isDoc       := eq .Section "docs" }}
{{ $title       := cond $isHome site.Title .Title }}
{{ $description := .Param "description" }}
{{ $pageType    := cond $isHome "website" "article" }}
{{ $imageUrl    := "/img/logos/opa-horizontal-color.png" | absURL }}
{{ $twitter     := site.Params.social.twitter }}
{{ $page        := trim .RelPermalink "/" }}
{{ $releases    := site.Data.releases }}
{{ $latest      := index $releases 1 }}
{{ $isLatest    := or (eq $version $latest) (eq $version "latest") }}


<!-- Basic metadata -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
{{ with $description }}
<meta name="description" content="{{ . }}">
{{ end }}

<!-- OpenGraph metadata -->
<meta property="og:title" content="{{ $title }}">
{{ if $isDoc }}
<meta property="og:type" content="documentation">
{{ end }}
<meta property="og:url" content="{{ .Permalink }}">
<meta property="og:locale" content="en_US">
{{ if not $isHome }}
<meta property="og:site_name" content="{{ site.Title }}">
{{ end }}
{{ with $description }}
<meta property="og:description" content="{{ . }}">
{{ end }}
<meta name="og:type" content="{{ $pageType }}">
<meta name="og:image" content="{{ $imageUrl }}">
<meta name="og:image:alt" content="Open Policy Agent project logo">
<meta name="og:image:type" content="image/png">

<!-- TwitterCard metadata -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@{{ $twitter }}">
<meta name="twitter:creator" content="@{{ $twitter }}">

{{ $latestRelLink := strings.Replace $page $version "latest" }}
{{ $latestLink := strings.Replace .Permalink $version "latest" }}
{{- if (or $isLatest (eq $version "edge") (ne (site.GetPage $latestRelLink).Content "")) -}}
<link rel="canonical" href="{{ $latestLink }}">
{{- end -}}
<link rel="shortcut icon" href="/favicon.png" type="image/x-icon"/>

<!-- Algolia metadata -->
<meta name="docsearch:language" content="en" />
<meta name="docsearch:version" content="{{ $version }}" />

<!-- Site generator -->
{{ hugo.Generator }}