<aside class="order-last md:order-none md:col-span-1">
  <!-- Article stats widget -->
  <div class="sidebar-widget">
    <p class="sidebar-widget-label"># {{ i18n "articleStats" }}</p>

    {{ if .Params.image }}
    <img
      src="{{ .Params.image }}"
      alt="{{ .Title }}"
      loading="lazy"
      class="w-full rounded mb-4 object-cover max-h-40"
    >
    {{ end }}

    <ul class="space-y-2 text-sm text-text-dim">
      <li class="flex items-center gap-2">
        <i data-feather="user" class="w-4 h-4 shrink-0" aria-hidden="true"></i>
        <span>{{ .Site.Params.author }}</span>
      </li>
      {{ if .PublishDate }}
      <li class="flex items-center gap-2">
        <i data-feather="calendar" class="w-4 h-4 shrink-0" aria-hidden="true"></i>
        <time datetime="{{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }}">
          {{ .PublishDate.Format "Jan 2, 2006" }}
        </time>
      </li>
      {{ end }}
      {{ if .Lastmod }}
        {{ $lastmodDate := .Lastmod.Format "2006-01-02" }}
        {{ $pubDate := .PublishDate.Format "2006-01-02" }}
        {{ if ne $lastmodDate $pubDate }}
        <li class="flex items-center gap-2">
          <i data-feather="edit-2" class="w-4 h-4 shrink-0" aria-hidden="true"></i>
          <time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">
            {{ .Lastmod.Format "Jan 2, 2006" }}
          </time>
        </li>
        {{ end }}
      {{ end }}
      <li class="flex items-center gap-2">
        <i data-feather="file-text" class="w-4 h-4 shrink-0" aria-hidden="true"></i>
        <span>{{ .WordCount }} {{ i18n "words" }}</span>
      </li>
      {{ if .Site.Params.readingTime }}
      <li class="flex items-center gap-2">
        <i data-feather="clock" class="w-4 h-4 shrink-0" aria-hidden="true"></i>
        <span>{{ .ReadingTime }} {{ i18n "min" }} {{ i18n "readingTime" }}</span>
      </li>
      {{ end }}
      {{ $articleType := .Params.type | default "" }}
      {{ $typeConfig := .Site.Params.articleTypes }}
      {{ $typeData := index $typeConfig $articleType }}
      {{ if and $typeData $articleType }}
      <li class="flex items-center gap-2">
        <i data-feather="tag" class="w-4 h-4 shrink-0" aria-hidden="true"></i>
        <span
          class="inline-flex items-center px-2.5 py-1 rounded text-sm font-mono font-semibold whitespace-nowrap transition-all duration-200"
          style="background-color: var(--type-{{ $articleType }}); border: 1px solid var(--type-{{ $articleType }}); color: var(--type-{{ $articleType }}-text);"
        >{{ i18n $articleType }}</span>
      </li>
      {{ end }}
    </ul>
  </div>

  {{- if and (eq .Section "is") (eq .Kind "section") }}
  <hr class="sidebar-hr">
  {{- partial "contribution-graph.html" (dict "cellSize" 8 "page" .) -}}
  {{- end }}

  <hr class="sidebar-hr">

  <!-- Social sharing widget -->
  {{ partial "social-share.html" (dict "page" . "mode" "sidebar") }}

  <!-- Related posts widget (articles only) -->
  {{ if and .Site.Params.relatedPosts (eq .Section "articles") }}
  {{ $related := first 5 (.Site.RegularPages.Related .) }}
  <hr class="sidebar-hr">
  <div class="sidebar-widget">
    <p class="sidebar-widget-label"># {{ i18n "relatedPosts" }}</p>
    {{ if $related }}
    <ul class="space-y-3">
      {{ range $related }}
      {{ $articleType := .Params.type | default "life" }}
      {{ $excerpt := .Params.excerpt | default .Description | default .Summary }}
      <li
        class="pl-3 border-l-2"
        style="border-color: var(--type-{{ $articleType }});"
      >
        <a href="{{ .RelPermalink }}" class="text-sm hover:text-accent transition-colors leading-snug block">
          {{ .Title }}
          <time class="text-text-dim/60 ml-1" datetime="{{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }}">
            · {{ .PublishDate.Format "Jan 2006" }}
          </time>
        </a>
        {{ if $excerpt }}
        <p class="text-xs text-text-dim/70 leading-snug mt-0.5 line-clamp-1">
          {{ $excerpt | plainify | truncate 60 }}
        </p>
        {{ end }}
      </li>
      {{ end }}
    </ul>
    {{ else }}
    <p class="text-sm text-text-dim">{{ i18n "noRelated" }}</p>
    {{ end }}
  </div>
  {{ end }}

  <hr class="sidebar-hr">

  <!-- Tag Cloud Widget -->
  {{ partial "tag-cloud.html" (dict "page" . "showCount" false "wrapInWidget" true "maxTags" 15) }}
</aside>
