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 = "" favicon = ""
[params.widgets] [params.widgets]
enabled = ['archive', 'tag-cloud'] enabled = ['archive', 'tag-cloud']
[params.widgets.archive]
limit = 5
[params.widgets.tagCloud] [params.widgets.tagCloud]
limit = 10 limit = 10
[params.opengraph] [params.opengraph]

View file

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