{{ define "main" }}
{{- $pages := where .Site.RegularPages "Section" "posts" }}
{{- $paginator := .Paginate $pages }}
<ul class="post-list">
  {{- range $paginator.Pages }}
  <li class="post-list__entry">
    <div class="post-list__meta">
      <time class="post-list__date" datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date.Format "Jan 2, 2006" }}</time>
      {{- with .Params.categories }}
      <span class="post-list__category">{{ index . 0 | lower }}</span>
      {{- end }}
    </div>
    <div class="post-list__body">
      <a href="{{ .Permalink }}" class="post-list__title">{{ .Title }}</a>
      {{- /* Use frontmatter description first (richer for Morning Brief posts),
             fall back to auto-generated summary */}}
      {{- $excerpt := or .Description (.Summary | plainify) }}
      {{- if $excerpt }}
      <p class="post-list__excerpt">{{ $excerpt | truncate 220 }}</p>
      {{- end }}
    </div>
  </li>
  {{- end }}
</ul>

{{- /* Pagination controls — only shown when there's more than one page */}}
{{- if gt $paginator.TotalPages 1 }}
<nav class="post-list-pagination" aria-label="Post navigation">
  <span>
    {{- if $paginator.HasPrev }}
    <a href="{{ $paginator.Prev.URL | absURL }}">← Newer posts</a>
    {{- end }}
  </span>
  <span>Page {{ $paginator.PageNumber }} of {{ $paginator.TotalPages }}</span>
  <span>
    {{- if $paginator.HasNext }}
    <a href="{{ $paginator.Next.URL | absURL }}">Older posts →</a>
    {{- end }}
  </span>
</nav>
{{- end }}
{{ end }}
