Skip to content

Commit

Permalink
taxonomy-list.html: Get arguments from dictionary instead of scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo3418 committed Mar 8, 2024
1 parent da40169 commit 762db9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
20 changes: 10 additions & 10 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@
</section>

<footer class="page__meta">
{{- .Scratch.Set "taxonomy" "tags" }}
{{- .Scratch.Set "iconClass" "fas fa-fw fa-tags" }}
{{- partial "taxonomy-list.html" . }}

{{- .Scratch.Set "taxonomy" "categories" }}
{{- .Scratch.Set "iconClass" "fas fa-fw fa-folder-open" }}
{{- partial "taxonomy-list.html" . }}

{{- .Scratch.Delete "taxonomy" }}
{{- .Scratch.Delete "iconClass" }}
{{- partial "taxonomy-list.html" (dict
"page" .
"taxonomy" "tags"
"iconClass" "fas fa-fw fa-tags"
)}}
{{- partial "taxonomy-list.html" (dict
"page" .
"taxonomy" "categories"
"iconClass" "fas fa-fw fa-folder-open"
)}}
</footer>

{{- $partialPath := printf "post-paginations/%s.html" .Section }}
Expand Down
17 changes: 9 additions & 8 deletions layouts/partials/taxonomy-list.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{{/*
Provides an element that shows all terms in a taxonomy assigned to the current
page in the context.
Provides an element that shows all terms assigned to a page in a taxonomy.

Recognized parameters in .Scratch:
The context should be a dictionary with these key-value pairs:
- page: The page whose taxonomy is to be displayed
- taxonomy: The name of the taxonomy to show in the element
- iconClass: The class for the icon shown for the taxonomy
*/}}

{{- $taxonomy := .Scratch.Get "taxonomy" }}
{{- $iconClass := .Scratch.Get "iconClass" }}
{{- $page := .page }}
{{- $taxonomy := .taxonomy }}
{{- $iconClass := .iconClass }}

{{- if index .Params $taxonomy }}
{{- $taxonomyPage := urlize $taxonomy | .Site.GetPage }}
{{- if index $page.Params $taxonomy }}
{{- $taxonomyPage := urlize $taxonomy | site.GetPage }}
{{- $scratch := newScratch }}
{{- range $taxonomyPage.Data.Terms }}
{{- $scratch.SetInMap "taxonomyHomes" .Page.Title .Page.RelPermalink }}
Expand All @@ -23,7 +24,7 @@
{{ $taxonomyPage.Title }}{{ i18n "punctuationColon" | safeHTML }}
</strong>
<span itemprop="keywords">
{{- range $i, $term := index .Params $taxonomy }}
{{- range $i, $term := index $page.Params $taxonomy }}
{{- if gt $i 0 -}}
<span class="sep">
{{- i18n "punctuationCommaInList" | safeHTML -}}
Expand Down

0 comments on commit 762db9b

Please sign in to comment.