mirror of
https://github.com/tiennm99/hugo-blox-builder.git
synced 2026-09-06 16:19:54 +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 +0,0 @@
|
||||
<svg fill="none" viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg"><path d="m307.031 292.969h-14.062v14.062h14.062z" fill="#fff"/><path d="m600 0h-600v600h600z" fill="#fff"/><path d="m600 0h-600v600h600z" fill="#0056d2"/><g fill="#fff"><path d="m117.913 300.434c0-19.301 15.923-34.875 35.859-34.875 20.07 0 35.992 15.574 35.992 34.875 0 19.167-15.922 35.007-35.992 35.007-19.936 0-35.859-15.973-35.859-35.007zm54.725 0c0-9.583-8.43-18.104-18.866-18.104-10.303 0-18.598 8.521-18.598 18.104 0 9.717 8.429 18.236 18.598 18.236 10.436 0 18.866-8.519 18.866-18.236z"/><path d="m478.15 300.965c0-21.164 17.326-35.406 33.036-35.406 10.747 0 16.924 3.194 21.086 9.452l1.612-8.253h16.116v67.353h-16.116l-2.015-6.923c-4.701 5.059-10.61 8.253-20.546 8.253-15.713 0-33.173-13.577-33.173-34.476zm54.795-.133c0-10.247-8.463-18.502-18.936-18.502-10.341 0-18.668 8.388-18.668 18.771 0 9.316 8.461 17.702 18.668 17.702 10.607-.133 18.936-8.519 18.936-17.971z"/><path d="m458.833 274.982v-7.721h-17.101v66.211h17.101v-35.724c0-10.729 5.221-16.356 14.487-16.356.652 0 1.176 0 1.697.131l3.133-15.964c-8.875.131-15.272 3.14-19.317 9.423z"/><path d="m284.158 274.982v-7.721h-17.623l.135 66.211h17.625l-.137-35.724c0-10.729 5.382-16.356 14.801-16.356.672 0 1.209 0 1.75.131l3.228-15.964c-9.15.131-15.741 3.14-19.779 9.423z"/><path d="m196.654 307.776v-41.233h17.209v39.104c0 8.645 4.73 13.699 13.006 13.699 9.196 0 14.583-5.718 14.583-16.624v-36.179h17.209v67.3h-17.209v-7.845c-4.073 6.383-10.641 9.442-19.706 9.442-15.502.133-25.092-11.172-25.092-27.664z"/><path d="m365.945 300.369c0-18.867 13.621-34.942 34.985-34.809 19.893 0 33.913 15.942 33.913 34.541 0 1.861-.134 3.854-.401 5.582l-51.405-.133c2.004 8.104 8.678 13.816 18.693 13.949 6.141 0 12.685-2.259 16.69-7.308l11.885 9.567c-6.144 8.634-16.959 13.683-28.441 13.683-20.297-.265-35.919-15.411-35.919-35.072zm51.408-6.909c-.937-6.777-8.145-12.091-16.423-12.091-8.145 0-14.689 4.783-17.226 11.958z"/><path d="m303.937 319.559 15.522-8.073c2.542 5.558 7.76 8.734 14.984 8.734 6.691 0 9.234-2.118 9.234-5.029 0-10.721-36.93-4.234-36.93-28.853 0-13.631 12.043-20.779 26.894-20.779 11.239 0 21.274 4.897 26.76 14.163l-15.388 8.073c-2.272-4.5-6.555-7.015-12.041-7.015-5.352 0-7.894 1.854-7.894 4.897 0 10.456 36.93 3.837 36.93 28.853 0 12.97-10.704 20.911-27.966 20.911-14.717-.132-25.02-4.897-30.105-15.882z"/><path d="m50 300.074c0-19.161 15.7897-34.515 35.5599-34.515 12.7377 0 23.7511 6.301 30.1201 15.747l-14.861 8.532c-3.4503-4.724-8.8902-7.873-15.2591-7.873-10.2169 0-18.4434 8.398-18.4434 17.978 0 9.578 8.359 17.976 18.4434 17.976 6.6342 0 12.4724-3.411 15.6571-8.529l14.728 8.66c-6.236 9.843-17.5148 16.406-30.3851 16.406-19.7702.131-35.5599-15.616-35.5599-34.382z"/></g></svg>
|
||||
|
Before Width: | Height: | Size: 2.7 KiB |
@@ -1 +0,0 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 34"><path d="M14.001 25.028v-7.224l11.393-6.498-2.77-1.588-8.623 4.918V7.391c0-.491-.265-.95-.69-1.194L2.938.245a1.974 1.974 0 00-2.006.06A1.98 1.98 0 000 1.992v20.375c0 .69.35 1.321.934 1.687a1.973 1.973 0 002.002.061l8.317-4.743v6.457c0 .494.266.952.695 1.196l10.658 6.067 2.771-1.589-11.376-6.475zm-2.748-16.84v8.016l-8.504 4.85V3.31l8.504 4.88z" fill="#03EF62" fill-rule="evenodd"></path></svg>
|
||||
|
Before Width: | Height: | Size: 469 B |
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 24.1.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 552.88 310.72" style="enable-background:new 0 0 552.88 310.72;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#02262B;}
|
||||
.st1{fill:#FFFFFF;}
|
||||
</style>
|
||||
<polygon class="st0" points="353.43,50.96 364.08,0 51.3,0 0,245.01 261.52,245.01 247.12,310.72 497.63,310.72 552.88,50.96 "/>
|
||||
<path class="st1" d="M106.6,213.73c-7.09,0-13.79-1.16-20.09-3.49c-6.3-2.32-11.8-5.75-16.49-10.28
|
||||
c-4.69-4.53-8.39-10.1-11.11-16.72c-2.72-6.62-4.08-14.22-4.08-22.81c0-11.74,1.63-22.44,4.9-32.09
|
||||
c3.27-9.65,7.82-17.92,13.65-24.82c5.83-6.89,12.82-12.23,20.98-16.01c8.15-3.78,17.08-5.67,26.77-5.67
|
||||
c6.54,0,12.74,1.14,18.62,3.43c5.87,2.29,11.01,5.61,15.42,9.99c4.41,4.37,7.92,9.75,10.52,16.13c2.6,6.38,3.9,13.71,3.9,21.98
|
||||
c0,1.26-0.04,2.74-0.12,4.43c-0.08,1.7-0.2,3.43-0.36,5.2c-0.16,1.77-0.32,3.51-0.47,5.2c-0.16,1.69-0.35,3.13-0.59,4.31H76.22
|
||||
c-0.08,1.11-0.14,2.17-0.18,3.19c-0.04,1.03-0.06,2.09-0.06,3.19c0,6.54,0.95,12.11,2.84,16.72c1.89,4.61,4.35,8.37,7.39,11.29
|
||||
c3.03,2.92,6.44,5.02,10.22,6.32c3.78,1.3,7.6,1.95,11.46,1.95c8.43,0,15.21-1.46,20.33-4.37c5.12-2.91,9.02-6.85,11.7-11.82h21.63
|
||||
c-1.34,4.89-3.55,9.46-6.62,13.71c-3.07,4.25-6.95,7.94-11.64,11.05c-4.69,3.11-10.13,5.56-16.31,7.33
|
||||
C120.8,212.84,114,213.73,106.6,213.73z M148.08,136.08c0.08-0.39,0.14-1.12,0.18-2.19c0.04-1.06,0.06-2.11,0.06-3.13
|
||||
c0-4.18-0.61-8.14-1.83-11.88c-1.22-3.74-3.05-7.03-5.5-9.87c-2.44-2.84-5.48-5.08-9.1-6.74c-3.63-1.65-7.84-2.48-12.65-2.48
|
||||
c-4.89,0-9.46,0.87-13.71,2.6c-4.26,1.73-8.12,4.2-11.58,7.39c-3.47,3.19-6.46,7.01-8.98,11.46c-2.52,4.45-4.53,9.4-6.03,14.83
|
||||
H148.08z"/>
|
||||
<path class="st1" d="M227.58,213.73c-6.38,0-12.37-1.2-17.97-3.61c-5.6-2.4-10.5-5.85-14.71-10.34c-4.22-4.49-7.55-9.93-9.99-16.31
|
||||
c-2.44-6.38-3.66-13.51-3.66-21.39c0-7.64,0.77-14.95,2.3-21.92s3.72-13.43,6.56-19.38c2.84-5.95,6.24-11.33,10.22-16.13
|
||||
c3.98-4.81,8.39-8.9,13.24-12.29c4.85-3.39,10.08-5.99,15.72-7.8c5.63-1.81,11.52-2.72,17.67-2.72c4.57,0,8.92,0.63,13.06,1.89
|
||||
c4.14,1.26,7.88,3.01,11.23,5.26c3.35,2.25,6.22,4.96,8.63,8.15c2.4,3.19,4.16,6.68,5.26,10.46h1.89l15.72-74.11h20.68l-37.82,178
|
||||
h-19.62l3.66-17.37h-1.89c-4.65,6.07-10.48,10.85-17.49,14.36C243.26,211.97,235.69,213.73,227.58,213.73z M234.08,195.41
|
||||
c6.62,0,12.74-1.55,18.38-4.67c5.63-3.11,10.54-7.37,14.71-12.76c4.18-5.4,7.45-11.74,9.81-19.03c2.36-7.29,3.55-15.15,3.55-23.58
|
||||
c0-5.44-0.75-10.32-2.25-14.66c-1.5-4.33-3.63-8.02-6.38-11.05c-2.76-3.03-6.11-5.38-10.05-7.03c-3.94-1.66-8.39-2.48-13.36-2.48
|
||||
c-6.54,0-12.61,1.46-18.2,4.37c-5.6,2.92-10.44,6.97-14.54,12.17c-4.1,5.2-7.33,11.41-9.69,18.61s-3.55,15.11-3.55,23.7
|
||||
c0,5.36,0.77,10.28,2.31,14.77c1.54,4.49,3.68,8.33,6.44,11.52c2.76,3.19,6.07,5.67,9.93,7.45
|
||||
C225.05,194.52,229.35,195.41,234.08,195.41z"/>
|
||||
<g>
|
||||
<polygon class="st1" points="508.94,84.45 462.81,84.45 412.49,146.75 410.01,146.75 383.4,84.45 336.74,84.45 376.74,174.94
|
||||
290.39,277.23 335.9,277.23 391.32,211.52 395.06,211.52 425,277.23 470.79,277.23 426.51,179.47 "/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 3.1 KiB |
File diff suppressed because one or more lines are too long
@@ -0,0 +1,9 @@
|
||||
# HugoBlox icon aliases — survives icon pack updates.
|
||||
# Format: pack/old-name → pack/new-name (or cross-pack)
|
||||
#
|
||||
# Each entry maps <pack>/<alias> → <pack>/<canonical>
|
||||
# If the target pack differs, specify it explicitly.
|
||||
|
||||
brands:
|
||||
google-scholar: googlescholar
|
||||
weixin: wechat
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1523
-687
File diff suppressed because one or more lines are too long
@@ -27,5 +27,7 @@ icons:
|
||||
cat: <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 256 256"><path d="M96,140a12,12,0,1,1-12-12A12,12,0,0,1,96,140Zm76-12a12,12,0,1,0,12,12A12,12,0,0,0,172,128Zm60-80v88c0,52.93-46.65,96-104,96S24,188.93,24,136V48A16,16,0,0,1,51.31,36.69c.14.14.26.27.38.41L69,57a111.22,111.22,0,0,1,118.1,0L204.31,37.1c.12-.14.24-.27.38-.41A16,16,0,0,1,232,48Zm-16,0-21.56,24.8A8,8,0,0,1,183.63,74,88.86,88.86,0,0,0,168,64.75V88a8,8,0,1,1-16,0V59.05a97.43,97.43,0,0,0-16-2.72V88a8,8,0,1,1-16,0V56.33a97.43,97.43,0,0,0-16,2.72V88a8,8,0,1,1-16,0V64.75A88.86,88.86,0,0,0,72.37,74a8,8,0,0,1-10.81-1.17L40,48v88c0,41.66,35.21,76,80,79.67V195.31l-13.66-13.66a8,8,0,0,1,11.32-11.31L128,180.68l10.34-10.34a8,8,0,0,1,11.32,11.31L136,195.31v20.36c44.79-3.69,80-38,80-79.67Z"></path></svg>
|
||||
person-simple-walk: <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 256 256"><path d="M152,80a32,32,0,1,0-32-32A32,32,0,0,0,152,80Zm0-48a16,16,0,1,1-16,16A16,16,0,0,1,152,32Zm64,112a8,8,0,0,1-8,8c-35.31,0-52.95-17.81-67.12-32.12-2.74-2.77-5.36-5.4-8-7.84l-13.43,30.88,37.2,26.57A8,8,0,0,1,160,176v56a8,8,0,0,1-16,0V180.12l-31.07-22.2L79.34,235.19A8,8,0,0,1,72,240a7.84,7.84,0,0,1-3.19-.67,8,8,0,0,1-4.15-10.52l54.08-124.37c-9.31-1.65-20.92,1.2-34.7,8.58a163.88,163.88,0,0,0-30.57,21.77a8,8,0,0,1-10.95-11.66c2.5-2.35,61.69-57.23,98.72-25.08,3.83,3.32,7.48,7,11,10.57C166.19,122.7,179.36,136,208,136A8,8,0,0,1,216,144Z"></path></svg>
|
||||
|
||||
cv: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" style="stroke-width:.07717" d="M249.18 328.324c-9.788 15.384-19.179 30.434-40.222 45.055-11.256 7.89-37.164 23.306-73.99 23.306C64.709 396.685 8 345.605 8 255.801c0-78.486 53.345-140.486 128.466-140.486 30.434 0 57.474 10.521 77.387 26.304 18.414 14.65 27.038 29.304 34.563 42.456l-52.58 26.273c-3.762-8.626-8.29-17.649-19.913-27.406-12.784-10.155-25.54-13.152-36.46-13.152-42.821 0-65.364 39.825-65.364 84.145 0 58.238 29.7 87.143 65.364 87.143 34.563 0 48.48-24.042 57.474-39.426l52.243 26.673zm184.194-204.75H504l-92.037 265.22h-67.597l-90.904-265.22h70.625l54.843 188.6z"/></svg>
|
||||
|
||||
# Git icons
|
||||
git-fork: <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24"><path d="M6 2C4.89543 2 4 2.89543 4 4C4 4.74028 4.4022 5.38663 5 5.73244V7C5 8.65685 6.34315 10 8 10H10V11.2676C9.4022 11.6134 9 12.2597 9 13C9 14.1046 9.89543 15 11 15C12.1046 15 13 14.1046 13 13C13 12.2597 12.5978 11.6134 12 11.2676V10H14C15.6569 10 17 8.65685 17 7V5.73244C17.5978 5.38663 18 4.74028 18 4C18 2.89543 17.1046 2 16 2C14.8954 2 14 2.89543 14 4C14 4.74028 14.4022 5.38663 15 5.73244V7C15 7.55228 14.5523 8 14 8H8C7.44772 8 7 7.55228 7 7V5.73244C7.5978 5.38663 8 4.74028 8 4C8 2.89543 7.10457 2 6 2ZM6 4C6 3.44772 6.44772 3 7 3C7.55228 3 8 3.44772 8 4C8 4.55228 7.55228 5 7 5C6.44772 5 6 4.55228 6 4ZM11 13C11 12.4477 11.4477 12 12 12C12.5523 12 13 12.4477 13 13C13 13.5523 12.5523 14 12 14C11.4477 14 11 13.5523 11 13ZM16 3C15.4477 3 15 3.44772 15 4C15 4.55228 15.4477 5 16 5C16.5523 5 17 4.55228 17 4C17 3.44772 16.5523 3 16 3Z"/></svg>
|
||||
|
||||
+5213
-3295
File diff suppressed because it is too large
Load Diff
@@ -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 -}}
|
||||
Reference in New Issue
Block a user