{{ $page := . }}

{{ $titles := slice }}

{{ if $page.IsHome }}
    {{ if and $page.Title site.Title (eq $page.Title site.Title) }}
        {{ $titles = slice (site.Title | markdownify | plainify | htmlUnescape) }}
    {{ else }}
        {{ if $page.Title }}
            {{ $titles = $titles | append ($page.Title | markdownify | plainify | htmlUnescape) }}
        {{ end }}

        {{ if site.Title }}
            {{ $titles = $titles | append (site.Title | markdownify | plainify | htmlUnescape) }}
        {{ end }}
    {{ end }}
{{ else }}
    {{ with $page.Title }}
        {{ $titles = slice (. | markdownify | plainify | htmlUnescape) }}
    {{ end }}

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

        {{ if and .IsHome (not $title) }}
            {{ $title = site.Title }}
        {{ end }}

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

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

<head>
    {{ partial "paige/func-include.html" (dict "name" "head-first%s.html" "page" $page) }}
    {{ partial "paige/metas.html" $page }}

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

    {{ partial "paige/links.html" $page }}
    {{ partial "paige/style.html" $page }}
    {{ partial "paige/func-include.html" (dict "name" "head-last%s.html" "page" $page) }}
</head>
