{{ $page := . }}

{{ $title := $page.Title }}

{{ if and $page.IsHome (not $title) }}
    {{ $title = $page.Param "paige.site_title" | default (site.Title) }}
{{ end }}

{{ $title = $title | markdownify | plainify | htmlUnescape }}

{{ $titles := slice $title }}

{{ range .Ancestors }}
    {{ $title := .Title }}

    {{ if and .IsHome (not $title) }}
        {{ $title = $page.Param "paige.site_title" | default (site.Title) }}
    {{ end }}

    {{ $titles = $titles | append ($title | markdownify | plainify | htmlUnescape) }}
{{ end }}

{{ $title = delimit $titles " · " }}

<head>
    {{ if templates.Exists "partials/paige/head-first.html" }}
        {{ partial "paige/head-first.html" $page }}
    {{ end }}

    {{ partial "paige/metas.html" $page }}

    {{ with $title }}
        <title>{{ . }}</title>
    {{ end }}

    {{ partial "paige/links.html" $page }}
    {{ partial "paige/style.html" $page }}

    {{ if templates.Exists "partials/paige/head-last.html" }}
        {{ partial "paige/head-last.html" $page }}
    {{ end }}
</head>
