Files
hugo-theme-stack/layouts/_partials/widget/archives.html
T

33 lines
1.4 KiB
HTML
Raw Normal View History

2022-02-26 23:45:25 +01:00
{{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "archives") -}}
{{- $context := .Context -}}
{{- $limit := default 5 .Params.limit -}}
{{- if $query -}}
{{- $archivesPage := index $query 0 -}}
<section class="widget archives">
<div class="widget-icon">
{{ partial "helper/icon" "infinity" }}
</div>
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
2020-08-22 13:20:08 +02:00
{{ $pages := partial "helper/pages.html" $context.Site.Home }}
{{ $archives := $pages.GroupByDate "2006" }}
<div class="widget-archive--list">
2022-02-26 23:45:25 +01:00
{{ range $index, $item := first (add $limit 1) ($archives) }}
{{- $id := lower (replace $item.Key " " "-") -}}
<div class="archives-year">
<a href="{{ $archivesPage.RelPermalink }}#{{ $id }}">
2022-02-26 23:45:25 +01:00
{{ if eq $index $limit }}
<span class="year">{{ T "widget.archives.more" }}</span>
{{ else }}
<span class="year">{{ .Key }}</span>
<span class="count">{{ len $item.Pages }}</span>
{{ end }}
</a>
</div>
{{ end }}
</div>
</section>
{{- else -}}
{{- warnf "Archives page not found. Create a page with layout: archives." -}}
{{- end -}}