{{ define "main" }}
<main class="post" id="main-content">
  {{ $hasToc := and (ne .Params.toc false) (gt (len (findRE "<li>" .TableOfContents)) 0) }}
  {{ $mobileToc := replace .TableOfContents `id="TableOfContents"` `id="MobileTableOfContents"` }}
  {{ $backHref := "/" | relURL }}
  {{ $backLabel := "Home" }}
  {{ if in (slice "projects" "websites") .Section }}
    {{ $backHref = "/projects/" | relURL }}
    {{ $backLabel = "Projects" }}
  {{ else if eq .Section "publications" }}
    {{ $backHref = "/publications/" | relURL }}
    {{ $backLabel = "Publications" }}
  {{ end }}
  <article class="post-layout{{ if $hasToc }} has-toc{{ end }}">
    {{ if $hasToc }}
      <aside class="post-margin" aria-label="Table of contents">
        <div class="toc">
          <div class="toc-title">Contents</div>
          {{ .TableOfContents }}
        </div>
      </aside>
    {{ end }}

    <div class="post-shell">
      <header class="post-header">
        <a class="back-link" href="{{ $backHref }}" aria-label="Back to {{ $backLabel }}" title="Back to {{ $backLabel }}">&lt; {{ $backLabel }}</a>

        <h1>{{ .Title }}</h1>

        <div class="post-meta">
          {{ if eq .Section "posts" }}
            <time datetime="{{ .Date.Format "2006-01-02" }}">
              {{ .Date.Format "02 Jan 2006" }}
            </time>
          {{ else }}
            <span>{{ .Section | singularize | title }}</span>
            {{ with .Params.status }}
              <span class="dot">·</span>
              <span>{{ . }}</span>
            {{ end }}
          {{ end }}
        </div>

        {{ with .Params.links }}
          <div class="item-links article-links">
            {{ $pageTitle := $.Title }}
            {{ range . }}
              <a href="{{ .url }}" aria-label="{{ .label }} for {{ $pageTitle }}" title="{{ .label }} for {{ $pageTitle }}">{{ .label }}</a>
            {{ end }}
          </div>
        {{ end }}

        {{ if $hasToc }}
          <details class="post-toc-inline">
            <summary>On this page</summary>
            <div class="post-toc-inline-body">
              {{ $mobileToc | safeHTML }}
            </div>
          </details>
        {{ end }}
      </header>

      <div class="post-content">
        {{ .Content }}
      </div>

      <footer class="post-footer">
        <a class="post-button" href="{{ $backHref }}" aria-label="Back to {{ $backLabel }}" title="Back to {{ $backLabel }}">&lt; {{ $backLabel }}</a>
        <a class="post-button" href="#main-content" aria-label="Scroll to top" title="Scroll to top">^ Top</a>
      </footer>
    </div>
  </article>
</main>
{{ end }}
