|
| 1 | +<!-- tags --> |
| 2 | +{{ if isset site.Taxonomies "tags" }} |
| 3 | + {{/* On category term pages, collect only tags present in this category's posts */}} |
| 4 | + {{ $filterByCategory := and (eq .Kind "term") (eq .Type "categories") }} |
| 5 | + {{ $categoryTagNames := slice }} |
| 6 | + {{ if $filterByCategory }} |
| 7 | + {{ range .Data.Pages }} |
| 8 | + {{ range .Params.tags }} |
| 9 | + {{ $categoryTagNames = $categoryTagNames | append (urlize .) }} |
| 10 | + {{ end }} |
| 11 | + {{ end }} |
| 12 | + {{ $categoryTagNames = $categoryTagNames | uniq }} |
| 13 | + {{ end }} |
| 14 | + |
| 15 | + {{ $tags := site.Taxonomies.tags }} |
| 16 | + {{ if not (eq (len $tags) 0) }} |
| 17 | + <div class="mb-8"> |
| 18 | + <h5 class="mb-6">{{ T "tags" }}</h5> |
| 19 | + <div class="bg-light dark:bg-darkmode-light rounded p-6"> |
| 20 | + <ul> |
| 21 | + {{ if $filterByCategory }} |
| 22 | + <li class="inline-block"> |
| 23 | + <a class="tag-filter-link hover:bg-primary dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-text-dark m-1 block rounded bg-white px-3 py-1 hover:text-white" |
| 24 | + href="{{ $.RelPermalink }}">All</a> |
| 25 | + </li> |
| 26 | + {{ end }} |
| 27 | + {{ range $name, $items := $tags }} |
| 28 | + {{ if or (not $filterByCategory) (in $categoryTagNames $name) }} |
| 29 | + <li class="inline-block"> |
| 30 | + {{ if $filterByCategory }} |
| 31 | + <a class="tag-filter-link hover:bg-primary dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-text-dark m-1 block rounded bg-white px-3 py-1 hover:text-white" |
| 32 | + href="?tag={{ $name }}"> |
| 33 | + {{ $items.Page.Title }} |
| 34 | + </a> |
| 35 | + {{ else }} |
| 36 | + {{ $isActive := and (eq $.Kind `term`) (eq $.Type `tags`) (eq $.Title $items.Page.Title) }} |
| 37 | + <a class="hover:bg-primary hover:text-white dark:hover:bg-darkmode-primary dark:hover:text-text-dark m-1 block rounded px-3 py-1 {{ if $isActive }}bg-primary text-white dark:bg-darkmode-primary dark:text-text-dark{{ else }}bg-white dark:bg-darkmode-body{{ end }}" |
| 38 | + href="{{ $items.Page.RelPermalink }}"> |
| 39 | + {{ $items.Page.Title }} |
| 40 | + </a> |
| 41 | + {{ end }} |
| 42 | + </li> |
| 43 | + {{ end }} |
| 44 | + {{ end }} |
| 45 | + </ul> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + {{ end }} |
| 49 | +{{ end }} |
0 commit comments