Add support for taxonomy and term on single page layout

This commit is contained in:
Justin Nguyen 2021-01-14 21:56:45 -08:00
parent 75f3e7bce2
commit 861da326d4
2 changed files with 47 additions and 30 deletions

View File

@ -146,22 +146,23 @@ paginate = 5
# oneHeadingSize = false # oneHeadingSize = false
# Single Page Sites have the links in their navigation menu point to sections on the # Single Page Sites have the links in their navigation menu point to sections on the
# main-single page. If `singlePageSite` is enabled the following will occur: # main-single page. If `singlePageSite` is enabled all nav manu entries will be rendered
# - Sections will appear on the homepage corresponding to nav menu items with a url # on the homepage as homepage sections unless their identifier appears in the
# beginning with "/#". These sections draw their content from the homepage content # `homepageNavEntriesDontRender` parameter, in which they will not appear on the homepage.
# type directory (content/homepage/<somesection>.md). # - Nav menu items with a url beginning with "/#" are homepage only sections. These
# sections draw their content from the homepage content type directory
# (content/homepage/<somesection>.md).
# - Nav menu items not beginning with "/#" will be also be rendered as sections on the # - Nav menu items not beginning with "/#" will be also be rendered as sections on the
# homepage either as paginated lists or also as sections depending on what the url is # homepage either as paginated lists (like posts), as regular sections, or taxonomy depending on
# pointing to. # what the url is pointing to.
# - Nav menu items with their identifier in the `homepageNavEntriesDontRender` list will # The homepage sections may not render in the order that you expect. Use the `weight` menu parameter
# not be rendered on the homepage. # on the menu entries to make sure the homepage sections appear in the order you like.
# The homepage sections will be rendered in the order of the nav menu entries.
# enable the sngle page site mode described above # enable the sngle page site mode described above
singlePageSite = false singlePageSite = false
# for collections rendered on the hompage, you may want them to be paginated at a different # for collections rendered on the hompage, you may want them to be paginated at a different
# (usually smaller) count compared to the actual list pages # (usually smaller) count compared to the actual list pages. Default is 2
homepagePaginateCount = 2 homepagePaginateCount = 2
# If there is a nav menu entry you dont want rendered on the homepage, add the identifier here # If there is a nav menu entry you dont want rendered on the homepage, add the identifier here

View File

@ -22,6 +22,7 @@
{{ range .Site.Menus.main }} {{ range .Site.Menus.main }}
{{ if not (in $.Site.Params.homepageNavEntriesDontRender .Identifier) }} {{ if not (in $.Site.Params.homepageNavEntriesDontRender .Identifier) }}
<section id="{{ .Identifier }}" class="posts section"> <section id="{{ .Identifier }}" class="posts section">
{{ $navLinkPage := $.Site.GetPage .URL }}
{{ if eq (first 2 .URL) "/#" }} {{ if eq (first 2 .URL) "/#" }}
<h1 class="section-header">{{ .Name }}<a href="#{{ .Identifier }}" class="hanchor" arialabel="Anchor"></a></h1> <h1 class="section-header">{{ .Name }}<a href="#{{ .Identifier }}" class="hanchor" arialabel="Anchor"></a></h1>
<div class="post"> <div class="post">
@ -30,28 +31,43 @@
{{ partial "section.html" . }} {{ partial "section.html" . }}
{{ end }} {{ end }}
</div> </div>
{{ else }} {{ else if in "section term" $navLinkPage.Kind }}
<h1 class="section-header">{{ .Name }}<a href="{{ .URL }}" class="hanchor" arialabel="Anchor"></a></h1> <h1 class="section-header">{{ .Name }}<a href="{{ .URL }}" class="hanchor" arialabel="Anchor"></a></h1>
{{ $thisSectionsPages := where $PageContext.RegularPages "Type" .Identifier }} {{ $paginateCount := default 2 $.Site.Params.homepagePaginateCount }}
{{ if len $thisSectionsPages }} {{ range first $paginateCount $navLinkPage.Pages.ByDate.Reverse }}
{{ range first $.Site.Params.homepagePaginateCount $thisSectionsPages.ByDate.Reverse }} {{ partial "collection.html" . }}
{{ partial "collection.html" . }}
{{ end }}
<div class="pagination">
<div class="pagination__buttons">
<span class="button previous">
<a href="{{ .URL }}">
<span class="button__icon"></span>
<span class="button__text">See more {{ .Name | pluralize }}</span>
</a>
</span>
</div>
</div>
{{ else }}
{{ with $.Site.GetPage .URL }}
{{ partial "section.html" . }}
{{ end }}
{{ end }} {{ end }}
<div class="pagination">
<div class="pagination__buttons">
<span class="button previous">
<a href="{{ .URL }}">
<span class="button__icon"></span>
<span class="button__text">See more {{ .Name | pluralize }}</span>
</a>
</span>
</div>
</div>
{{ else if eq $navLinkPage.Kind "page" }}
{{ partial "section.html" $navLinkPage }}
{{ else if eq $navLinkPage.Kind "taxonomy" }}
<h1 class="section-header">{{ .Name }}<a href="{{ .URL }}" class="hanchor" arialabel="Anchor"></a></h1>
<div class="terms">
<ul>
{{ range $key, $value := $navLinkPage.Data.Terms.Alphabetical }}
{{ $name := .Name }}
{{ $count := .Count }}
{{ with $.Site.GetPage (printf "/%s/%s" "tags" $name) }}
<li>
<a class="terms-title" href="{{ .Permalink }}">{{ .Name }} ({{ $count }})</a>
</li>
{{ end }}
{{ end }}
</ul>
</div>
{{ else if eq $navLinkPage.Kind "taxonomy" }}
<h1 class="section-header">{{ .Name }}<a href="{{ .URL }}" class="hanchor" arialabel="Anchor"></a></h1>
{{ else }}
{{ $navLinkPage.Kind }} is not supported yet.
{{ end }} {{ end }}
</section> </section>
<hr class="section-separator"> <hr class="section-separator">