Refactor into generic list
This commit is contained in:
parent
a4581e255f
commit
c0a446c112
@ -1,5 +1,5 @@
|
|||||||
{{ define "main" }}
|
{{ define "main" }}
|
||||||
{{ partial "snippet-list" (dict "showAllArticles" true) }}
|
{{ partial "snippet-list" (dict "showViewAllButton" true) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "aside" }}
|
{{ define "aside" }}
|
||||||
|
|||||||
30
layouts/partials/generic-list.html
Normal file
30
layouts/partials/generic-list.html
Normal 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>
|
||||||
@ -1,24 +1,3 @@
|
|||||||
<section class="list">
|
{{ $showViewAllButton := or (index $ "showViewAllButton") false }}
|
||||||
<div class="header">
|
|
||||||
<h3>Latest Articles</h3>
|
|
||||||
|
|
||||||
{{ if index $ "showAllArticles" }}
|
{{ partial "generic-list" (dict "labelSingular" "snippet" "pageType" "snippets" "showViewAllButton" $showViewAllButton) }}
|
||||||
<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>
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user