archives.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. {{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "archives") -}}
  2. {{- $context := .Context -}}
  3. {{- $limit := default 5 .Params.limit -}}
  4. {{- if $query -}}
  5. {{- $archivesPage := index $query 0 -}}
  6. <section class="widget archives">
  7. <div class="widget-icon">
  8. {{ partial "helper/icon" "infinity" }}
  9. </div>
  10. <h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
  11. {{ $pages := where $context.Site.RegularPages "Type" "in" $context.Site.Params.mainSections }}
  12. {{ $notHidden := where $context.Site.RegularPages "Params.hidden" "!=" true }}
  13. {{ $filtered := ($pages | intersect $notHidden) }}
  14. {{ $archives := $filtered.GroupByDate "2006" }}
  15. <div class="widget-archive--list">
  16. {{ range $index, $item := first (add $limit 1) ($archives) }}
  17. {{- $id := lower (replace $item.Key " " "-") -}}
  18. <div class="archives-year">
  19. <a href="{{ $archivesPage.RelPermalink }}#{{ $id }}">
  20. {{ if eq $index $limit }}
  21. <span class="year">{{ T "widget.archives.more" }}</span>
  22. {{ else }}
  23. <span class="year">{{ .Key }}</span>
  24. <span class="count">{{ len $item.Pages }}</span>
  25. {{ end }}
  26. </a>
  27. </div>
  28. {{ end }}
  29. </div>
  30. </section>
  31. {{- else -}}
  32. {{- warnf "Archives page not found. Create a page with layout: archives." -}}
  33. {{- end -}}