Files
HugoBlox-kit/layouts/partials/widgets/posts.html
T
George Cushen fbcb7f2761 feat(widget): restrict post filter to only one tag or category
Close #815

BREAKING CHANGES

Remove `tags_include` and `tags_exclude` from `home/posts.md`
Add `filter_tag` and `filter_category` to `home/posts.md`
2018-12-16 00:48:51 +00:00

50 lines
1.5 KiB
HTML

{{ $ := .root }}
{{ $page := .page }}
{{ $query := where (where $.Site.RegularPages "Type" "post") ".Params.notonhomepage" nil }}
{{ $archive_page := $.Site.GetPage "section" "post" }}
{{/* Check if a filter should be applied. */}}
{{ if $page.Params.filter_tag }}
{{ $archive_page = $.Site.GetPage (printf "tags/%s" $page.Params.filter_tag) }}
{{ $query = $query | intersect $archive_page.Pages }}
{{ else if $page.Params.filter_category }}
{{ $archive_page = $.Site.GetPage (printf "categories/%s" $page.Params.filter_category) }}
{{ $query = $query | intersect $archive_page.Pages }}
{{ end }}
{{ $count := len ($query) }}
<!-- Blog Posts widget -->
<div class="row">
<div class="col-12 col-lg-4 section-heading">
<h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
{{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
{{ if gt $count $page.Params.count }}
<p class="view-all">
<a href="{{ $archive_page.RelPermalink }}">
{{ i18n "more_posts" | markdownify }}
<i class="fas fa-angle-double-right"></i>
</a>
</p>
{{ end }}
</div>
<div class="col-12 col-lg-8">
{{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
{{ range $post := first $page.Params.count $query }}
{{ if eq $page.Params.list_format 0 }}
{{ partial "post_li_simple" . }}
{{ else if eq $page.Params.list_format 1 }}
{{ partial "post_li_detailed" . }}
{{ else }}
{{ partial "post_li_stream" . }}
{{ end }}
{{end}}
</div>
</div>