mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-16 02:15:13 +00:00
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:
1 parent
2bb78df692
commit
5733b053bb
13 files changed
+18841
-4737
No files matched your search
@@ -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 -}}
|
||||
Reference in new issue
Block a user