feat(icons): expand brands icon pack and update all packs

Also, refactor icon resolution to avoid duplicated logic:

get_icon_svg.html	New shared core — alias resolution, pack lookup, hb fallback, user assets, hugo fallback. Returns raw SVG string.

get_icon.html	Thin wrapper — emoji handling, calls get_icon_svg, Unicode emoji fallback for bare names, attribute injection, safeHTML return.

get_icon_data.html	Thin wrapper — one-liner delegating to get_icon_svg.
This commit is contained in:
George Cushen committed 2026-03-27 00:19:41 +00:00
1 parent 2bb78df692
commit 5733b053bb
13 files changed
+18841 -4737

No files matched your search

@@ -1,5 +1,5 @@
{{/* Return the requested SVG icon */}}
{{/* Search for the icon in the Hugo Blox Kit icon library, falling back to user's icon library */}}
{{/* Return the requested SVG icon as safeHTML for Go template rendering.
Handles emoji packs and attribute injection on top of the shared get_icon_svg.html core. */}}
{{ $dirFile := path.Split .name }}
{{ $pack := .pack | default (strings.Replace $dirFile.Dir "/" "") | default "hero" }}
@@ -31,71 +31,24 @@
{{ $attrs = printf "%s %s" $attrs $style_attr }}
{{ $icon = printf "<span %s>%s</span>" $attrs $emoji }}
{{- else -}}
{{- $icon_pack := index site.Data.icons $pack -}}
{{- $pack_icon := index (index $icon_pack "icons") $name -}}
{{/* Try to resolve as an SVG icon from packs / user assets */}}
{{ $icon = partial "functions/get_icon_svg" (dict "name" .name "pack" (.pack | default "") "Page" .Page) }}
{{ if $pack_icon }}
{{ if in (slice "hb" "brands") $pack }}
{{ $icon = $pack_icon }}
{{/* Pass */}}
{{ else }}
{{ $icon_body := index $pack_icon "body" }}
{{ $icon_size := index $icon_pack "height" }}
{{ $icon = printf `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %s %s">%s</svg>` (cast.ToString $icon_size) (cast.ToString $icon_size) $icon_body }}
{{ end }}
{{ else }}
{{/* Icon NOT found in pack - check if it's a direct Unicode emoji */}}
{{ if not (strings.Contains $.name "/") }}
{{/* No explicit pack specified (defaulted to hero) - treat as direct Unicode emoji */}}
{{ $attrs := .attributes | default "" }}
{{/* Convert SVG sizing to emoji text sizing (same as emoji pack) */}}
{{ if in $attrs "w-24" }}{{ $attrs = replaceRE "w-24 h-24" "text-8xl" $attrs }}{{ end }}
{{ if in $attrs "w-16" }}{{ $attrs = replaceRE "w-16 h-16" "text-5xl" $attrs }}{{ end }}
{{ if in $attrs "w-12" }}{{ $attrs = replaceRE "w-12 h-12" "text-5xl" $attrs }}{{ end }}
{{ if in $attrs "w-8" }}{{ $attrs = replaceRE "w-8 h-8" "text-4xl" $attrs }}{{ end }}
{{ if in $attrs "w-6" }}{{ $attrs = replaceRE "w-6 h-6" "text-2xl" $attrs }}{{ end }}
{{ if in $attrs "w-5" }}{{ $attrs = replaceRE "w-5 h-5" "text-xl" $attrs }}{{ end }}
{{ if in $attrs "w-4" }}{{ $attrs = replaceRE "w-4 h-4" "text-lg" $attrs }}{{ end }}
{{/* Add centering and line-height classes if not already present */}}
{{ if not (in $attrs "flex") }}{{ $attrs = replaceRE "class=\"" "class=\"flex items-center justify-center leading-none " $attrs }}{{ end }}
{{ $icon = printf "<span %s>%s</span>" $attrs $.name }}
{{ else }}
{{/* Explicit pack specified but icon not found - continue with fallback logic */}}
{{ with index (index site.Data.icons.hb "icons") $name -}}
{{ $icon = . }}
{{ else }}
{{- $prefix := printf "media/icons/%s/" $pack -}}
{{- $icon_path := printf "%s%s.svg" $prefix $name -}}
{{- if not (fileExists (printf "assets/%s" $icon_path)) -}}
{{ $pageRef := "unknown location" }}
{{ if .Page }}
{{ if .Page.File }}
{{ if .Page.File.Path }}
{{ $pageRef = .Page.File.Path }}
{{ else if .Page.RelPermalink }}
{{ $pageRef = .Page.RelPermalink }}
{{ end }}
{{ else if .Page.RelPermalink }}
{{ $pageRef = .Page.RelPermalink }}
{{ end }}
{{ end }}
{{ partial "functions/logger" (dict
"page" .Page
"level" "warn"
"id" (printf "missing-icon-%s-%s" $pack $name)
"message" (printf "The icon `%s` was not found in `assets/media/icons/%s/`. Referenced in: %s" $name $pack $pageRef)
)
}}
{{- end -}}
{{- $icon_resource := resources.Get $icon_path -}}
{{ if $icon_resource }}
{{ $icon = $icon_resource.Content }}
{{ else }}
{{ $icon = index (index site.Data.icons.brands "icons") "hugo" }}
{{ end }}
{{- if not $icon -}}
{{/* No pack prefix and not found in hero — treat the raw name as a Unicode emoji */}}
{{ if not (strings.Contains $.name "/") }}
{{ $attrs := .attributes | default "" }}
{{ if in $attrs "w-24" }}{{ $attrs = replaceRE "w-24 h-24" "text-8xl" $attrs }}{{ end }}
{{ if in $attrs "w-16" }}{{ $attrs = replaceRE "w-16 h-16" "text-5xl" $attrs }}{{ end }}
{{ if in $attrs "w-12" }}{{ $attrs = replaceRE "w-12 h-12" "text-5xl" $attrs }}{{ end }}
{{ if in $attrs "w-8" }}{{ $attrs = replaceRE "w-8 h-8" "text-4xl" $attrs }}{{ end }}
{{ if in $attrs "w-6" }}{{ $attrs = replaceRE "w-6 h-6" "text-2xl" $attrs }}{{ end }}
{{ if in $attrs "w-5" }}{{ $attrs = replaceRE "w-5 h-5" "text-xl" $attrs }}{{ end }}
{{ if in $attrs "w-4" }}{{ $attrs = replaceRE "w-4 h-4" "text-lg" $attrs }}{{ end }}
{{ if not (in $attrs "flex") }}{{ $attrs = replaceRE "class=\"" "class=\"flex items-center justify-center leading-none " $attrs }}{{ end }}
{{ $icon = printf "<span %s>%s</span>" $attrs $.name }}
{{ end }}
{{ end }}
{{ end }}
{{- end -}}
{{- end -}}
{{ if .attributes }}
@@ -1,63 +1,14 @@
{{/* Hugo Blox: Get Icon Data for Preact Components */}}
{{/* Documentation: https://hugoblox.com/blocks/ */}}
{{/* License: https://github.com/HugoBlox/kit/blob/main/LICENSE.md */}}
{{/* Return raw SVG content for Preact component consumption.
Thin wrapper around get_icon_svg.html — see that partial for resolution logic.
{{/*
This partial returns raw SVG content for icons, designed for Preact component integration.
PURPOSE:
- Provides SVG strings that can be passed as props to Preact components
- Enables dynamic icon rendering in client-side Preact blocks
- Mirrors get_icon.html logic but returns raw content instead of safeHTML
DIFFERENCE FROM get_icon.html:
- get_icon.html: Returns safeHTML for direct template rendering in Go HTML templates
- get_icon_data.html: Returns raw SVG string for JavaScript/Preact component consumption
USAGE:
{{ $icon_svg := partial "functions/get_icon_data" (dict "name" "arrow-right" "pack" "hero") }}
Then pass $icon_svg as a prop to Preact components for client-side rendering.
ICON PACK HANDLING:
1. Hero pack (heroicons): Assembles <svg> wrapper around "body" content using pack "height"
2. HB/Brands packs: Returns stored SVG strings as-is
3. User assets: Returns content from assets/media/icons/{pack}/{name}.svg
4. Fallback: Returns Hugo brand icon if not found
PARAMETERS:
- name: Icon name, optionally with pack prefix (e.g., "arrow-right" or "hero/arrow-right")
- pack: Icon pack name (defaults to "hero" if not specified in name)
USAGE:
{{ $svg := partial "functions/get_icon_data" (dict "name" "hero/arrow-right") }}
Then pass $svg as a prop to a Preact component.
*/}}
{{/* Return the raw SVG content for a requested icon */}}
{{- $name := .name | default "" -}}
{{- $icon_content := "" -}}
{{- $icon := "" -}}
{{- if $name -}}
{{- $dirFile := path.Split $name -}}
{{- $pack := .pack | default (strings.Replace $dirFile.Dir "/" "") | default "hero" -}}
{{- $iconName := $dirFile.File -}}
{{- $icon_pack := index site.Data.icons $pack -}}
{{- with index (index $icon_pack "icons") $iconName -}}
{{- /* If this pack stores full SVG strings (hb/brands), return as-is. */ -}}
{{- if in (slice "hb" "brands") $pack -}}
{{- $icon_content = . -}}
{{- else -}}
{{- $icon_body := index . "body" -}}
{{- $icon_size := index $icon_pack "height" -}}
{{- $icon_content = printf `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %s %s">%s</svg>` (cast.ToString $icon_size) (cast.ToString $icon_size) $icon_body -}}
{{- end -}}
{{- else -}}
{{- with resources.GetMatch (path.Join "media" "icons" $pack (printf "%s.svg" $iconName)) -}}
{{- $icon_content = .Content -}}
{{- else -}}
{{- /* Fallback to a default icon if not found. */ -}}
{{- with index (index site.Data.icons.brands "icons") "hugo" -}}
{{- $icon_content = . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $icon = partial "functions/get_icon_svg" (dict "name" $name "pack" (.pack | default "")) -}}
{{- end -}}
{{- $icon_content -}}
{{- $icon -}}
@@ -0,0 +1,83 @@
{{/* Resolve an icon name to a raw SVG string.
Shared core used by get_icon.html (Go templates) and get_icon_data.html (Preact).
PARAMETERS:
- name: Icon name, optionally with pack prefix (e.g., "arrow-right" or "hero/arrow-right")
- pack: Icon pack name (defaults to "hero" if not specified in name)
- Page: (optional) Page context for logging missing icons
RETURNS: Raw SVG string, or empty string if not found.
RESOLUTION ORDER:
1. Alias resolution via data/icons/aliases.yaml
2. Named pack lookup (hb returns full SVG; others wrap body in <svg> tag)
3. Fallback to hb pack
4. User assets at assets/media/icons/{pack}/{name}.svg
5. Hugo brand icon as last resort (only when an explicit pack was specified)
*/}}
{{- $dirFile := path.Split .name -}}
{{- $pack := .pack | default (strings.Replace $dirFile.Dir "/" "") | default "hero" -}}
{{- $name := $dirFile.File -}}
{{- $explicitPack := or (.pack) (strings.Contains .name "/") -}}
{{- /* Resolve icon aliases (e.g. brands/google-scholar → brands/googlescholar) */ -}}
{{- with index site.Data.icons.aliases $pack -}}
{{- with index . $name -}}
{{- $name = . -}}
{{- end -}}
{{- end -}}
{{- $icon := "" -}}
{{- $icon_pack := index site.Data.icons $pack -}}
{{- $pack_icon := index (index $icon_pack "icons") $name -}}
{{- if $pack_icon -}}
{{- if eq $pack "hb" -}}
{{- $icon = $pack_icon -}}
{{- else -}}
{{- $icon_body := index $pack_icon "body" -}}
{{- $icon_size := index $icon_pack "height" -}}
{{- $icon = printf `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %s %s">%s</svg>` (cast.ToString $icon_size) (cast.ToString $icon_size) $icon_body -}}
{{- end -}}
{{- else -}}
{{- /* Icon not found in pack — try hb fallback, then user assets */ -}}
{{- with index (index site.Data.icons.hb "icons") $name -}}
{{- $icon = . -}}
{{- else -}}
{{- $prefix := printf "media/icons/%s/" $pack -}}
{{- $icon_path := printf "%s%s.svg" $prefix $name -}}
{{- $icon_resource := resources.Get $icon_path -}}
{{- if $icon_resource -}}
{{- $icon = $icon_resource.Content -}}
{{- else if $explicitPack -}}
{{- /* Only warn and use Hugo brand fallback when user specified an explicit pack */ -}}
{{- if not (fileExists (printf "assets/%s" $icon_path)) -}}
{{ $pageRef := "unknown location" }}
{{ if $.Page }}
{{ if $.Page.File }}
{{ if $.Page.File.Path }}
{{ $pageRef = $.Page.File.Path }}
{{ else if $.Page.RelPermalink }}
{{ $pageRef = $.Page.RelPermalink }}
{{ end }}
{{ else if $.Page.RelPermalink }}
{{ $pageRef = $.Page.RelPermalink }}
{{ end }}
{{ end }}
{{ partial "functions/logger" (dict
"page" $.Page
"level" "warn"
"id" (printf "missing-icon-%s-%s" $pack $name)
"message" (printf "The icon `%s` was not found in `assets/media/icons/%s/`. Referenced in: %s" $name $pack $pageRef)
)
}}
{{- end -}}
{{- with index (index site.Data.icons.brands "icons") "hugo" -}}
{{- $icon = printf `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">%s</svg>` (index . "body") -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- return $icon -}}