{{ partialCached "meta-common" . }}
<meta name="description" content="{{ .Page.Params.description | default .Site.Params.description | markdownify }}">
<meta property="og:url"             content="{{ .Permalink }}" />

{{if not .Page.IsHome }}
    <meta name="docsearch:modified" content='{{printf "%s" (.Page.Lastmod | time.Format ":date_long") }}' />
{{ end }}

{{ if .Page.Params.version }}
    {{if eq .Page.Params.version "master" }}
        <!-- "master" is not a SemVer version. Set it to 0.0.0 to derank it in search -->
        <meta name="docsearch:version" content="0.0.0-master" />
    {{ else }}
        <meta name="docsearch:version" content="{{.Page.Params.version}}" />
    {{ end }}
{{ end }}

{{ $ver := .Page.Params.version | default .Site.Params.latest }}

<title>
    {{- if .IsHome -}}{{- .Site.Title | markdownify }} · {{.Site.Params.subtitle | markdownify }} {{- else }}{{- .Title | markdownify}} · {{ .Site.Title | markdownify }} {{ if and (ne .Page.Params.version "0") (ne .Page.Params.version "master")}}v{{ $ver }}{{end}}{{if eq .Page.Params.version "master"}}{{.Page.Params.version }}{{end}}{{ end }}</title>


{{/* Don't do the URL processing for KB and Contrib guides */}}
{{ if not .Page.Params.Product }}
    {{/* Strip out the version from the path to get just the section + page */}}
    {{ $sectionPage := replaceRE (printf "v%s/" .Page.Params.version) "" .RelPermalink }}

    {{/* Handle the /latest directory */}}
    {{ if not .Page.Params.version }}
        {{ $sectionPage = replaceRE "/latest" "" .RelPermalink }}
    {{ end }}

    {{/* Handle the /master directory */}}
    {{ if eq .Page.Params.version "master" }}
        {{ $sectionPage = replaceRE "/master" "" .RelPermalink }}
    {{ end }}

    {{/* Strip training / so .GetPage works */}}
    {{ $sectionPage = strings.TrimRight "/" $sectionPage }}

    {{/* Look for the Page matching this page, but in the latest directory */}}
    {{ $latestPage := .Site.GetPage (printf "/latest%s" $sectionPage) }}

    {{/* If it exists set the canonical URL to the latest, otherwise we are canonical */}}
    {{ if $latestPage }}
    <link rel="canonical" href="{{$latestPage.Permalink }}">
    {{ end }}

{{ else }}
    <link rel="canonical" href="{{.Permalink}}">
{{ end }}

{{ partialCached "stylesheet-cached" . }}
{{ partial "stylesheet-dynamic" . }}
{{ partialCached "favicons" . }}

{{ partial "social" . }}

{{ with .OutputFormats.Get "rss" -}}
  {{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink site.Title | safeHTML }}
{{ end }}