Refactor into generic list

This commit is contained in:
Daniel_I_Am 2022-06-11 19:24:02 +02:00
parent a4581e255f
commit c0a446c112
3 changed files with 33 additions and 24 deletions

View File

@ -1,5 +1,5 @@
{{ define "main" }}
{{ partial "snippet-list" (dict "showAllArticles" true) }}
{{ partial "snippet-list" (dict "showViewAllButton" true) }}
{{ end }}
{{ define "aside" }}

View File

@ -0,0 +1,30 @@
{{ $labelSingular := index $ "labelSingular" }}
{{ $labelPlural := or (index $ "labelPlural") (print $labelSingular "s") }}
{{ $maximumListSize := or (index $ "maximumListSize") 3 }}
{{ $pageType := index $ "pageType"}}
{{ $viewAllHref := or (index $ "viewAllHref") (print "/" $labelPlural) }}
<section class="list">
<div class="header">
<h3>Latest {{ $labelPlural | title }}</h3>
{{ if index $ "showViewAllButton" }}
<div class="view-all">
<a href="{{ $viewAllHref }}">All {{ $labelPlural }}</a>
</div>
{{ end }}
</div>
<div class="list-items-container">
<ul class="list-items">
{{ range ( first $maximumListSize (where site.RegularPages "Type" $pageType).ByDate.Reverse ) }}
<li class="list-item" data-href="{{ .Permalink }}">
<img class="list-item-image" src="//via.placeholder.com/128" alt="{{ index $ "labelSingular" }} Topic">
<div class="list-item-text">
<h4 class="list-item-title">{{ .Title }}</h4>
<span class="list-item-date">{{ .Date.Format "January 2, 2006" }}</span>
</div>
</li>
{{ end }}
</ul>
</div>
</section>

View File

@ -1,24 +1,3 @@
<section class="list">
<div class="header">
<h3>Latest Articles</h3>
{{ $showViewAllButton := or (index $ "showViewAllButton") false }}
{{ if index $ "showAllArticles" }}
<div class="view-all">
<a href="javascript:void(0)">All articles</a>
</div>
{{ end }}
</div>
<div class="list-items-container">
<ul class="list-items">
{{ range ( first 3 (where site.RegularPages "Type" "snippets").ByDate.Reverse ) }}
<li class="list-item" data-href="{{ .Permalink }}">
<img class="list-item-image" src="//via.placeholder.com/128" alt="Article Topic">
<div class="list-item-text">
<h4 class="list-item-title">{{ .Title }}</h4>
<span class="list-item-date">{{ .Date.Format "January 2, 2006" }}</span>
</div>
</li>
{{ end }}
</ul>
</div>
</section>
{{ partial "generic-list" (dict "labelSingular" "snippet" "pageType" "snippets" "showViewAllButton" $showViewAllButton) }}