Files
FixIt/layouts/_partials/function/get-taxonomy-icon.html
T
Cell 1e0d1affaf feat(taxonomy): support taxonomy_icons with shared icon resolver and front matter icon overrides (#732)
- Added new config section: `params.taxonomy_icons`
  - Syntax: `<taxonomy> = [<title icon>, <card icon>, <term title icon>]`
- Added a shared resolver partial to centralize taxonomy icon lookup.
- Updated taxonomy-related templates to use the shared resolver instead of hardcoded icon maps.
- Added front matter overrides for taxonomy pages:
  - `titleIcon`
  - `cardIcon` (only for taxonomy `_index.md`)

Icon resolving priority now is:

1. Front matter override (`titleIcon` / `cardIcon`)
2. `params.taxonomy_icons` custom config
3. Built-in defaults (`tag`, `category`, `collection`)
2026-04-14 17:23:05 +08:00

25 lines
1.0 KiB
HTML

{{- /*
Resolve taxonomy icon by slot with site-level overrides.
@param {String} .Taxonomy taxonomy singular key, e.g. "tag", "category"
@param {String} .Slot icon slot: "title", "card", "term"
@return {String} icon class
*/ -}}
{{- $taxonomy := .Taxonomy | default "category" -}}
{{- $slot := .Slot | default "title" -}}
{{- $defaults := dict
"tag" (slice "fa-solid fa-tags" "fa-solid fa-tag" "fa-solid fa-tag")
"category" (slice "fa-solid fa-folder-tree" "fa-regular fa-folder" "fa-regular fa-folder-open")
"collection" (slice "fa-solid fa-layer-group" "fa-solid fa-layer-group" "fa-solid fa-layer-group")
-}}
{{- $fallback := index $defaults "category" -}}
{{- $icons := index $defaults $taxonomy | default $fallback -}}
{{- with index site.Params "taxonomy_icons" -}}
{{- with index . $taxonomy -}}
{{- $icons = . | default $icons -}}
{{- end -}}
{{- end -}}
{{- $slotIndex := index (dict "title" 0 "card" 1 "term" 2) $slot | default 0 -}}
{{- $icon := index $icons $slotIndex | default (index $fallback $slotIndex) -}}
{{- return $icon -}}