feat(widget/archive): add config to limit output number

This commit is contained in:
Jimmy Cai 2020-08-25 12:39:03 +02:00
parent 98c819b858
commit ff351ab294
2 changed files with 13 additions and 1 deletions

View File

@ -17,6 +17,8 @@ title = "Example Site"
favicon = ""
[params.widgets]
enabled = ['archive', 'tag-cloud']
[params.widgets.archive]
limit = 5
[params.widgets.tagCloud]
limit = 10
[params.opengraph]

View File

@ -7,7 +7,9 @@
{{ $v1 := where .Site.RegularPages "Section" "post" }}
{{ $v2 := where .Site.RegularPages "Params.hidden" "!=" true }}
{{ $filtered := $v1 | intersect $v2 }}
{{ range $filtered.GroupByDate "2006" }}
{{ $archive := $filtered.GroupByDate "2006" }}
{{ range first .Site.Params.widgets.archive.limit ($archive) }}
{{ $id := lower (replace .Key " " "-") }}
<div class="archive-year">
<a href="{{ $.Site.BaseURL }}/archive#{{ $id }}">
@ -16,4 +18,12 @@
</a>
</div>
{{ end }}
{{ if gt (len $archive) .Site.Params.widgets.archive.limit }}
<div class="archive-year">
<a href="{{ $.Site.BaseURL }}/archive">
<span class="year">More</span>
</a>
</div>
{{ end }}
</section>