From 54a643d703ac0882ef2d645c7f382b1bde134d01 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Fri, 25 Jul 2025 05:12:51 +0800 Subject: [PATCH] fix(icon): trim white spaces --- layouts/partials/icon.html | 8 ++++---- layouts/shortcodes/icon.html | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/layouts/partials/icon.html b/layouts/partials/icon.html index 150dc929..0e1c1baf 100644 --- a/layouts/partials/icon.html +++ b/layouts/partials/icon.html @@ -1,6 +1,6 @@ -{{ $icon := resources.Get (print "icons/" . ".svg") }} -{{ if $icon }} +{{- $icon := resources.Get (print "icons/" . ".svg") -}} +{{- if $icon -}} - {{ $icon.Content | safeHTML }} + {{- $icon.Content | safeHTML -}} -{{ end }} +{{- end -}} diff --git a/layouts/shortcodes/icon.html b/layouts/shortcodes/icon.html index 7203424d..167806d9 100644 --- a/layouts/shortcodes/icon.html +++ b/layouts/shortcodes/icon.html @@ -1,8 +1,10 @@ -{{ $icon := resources.Get (printf "icons/%s.svg" ($.Get 0)) }} -{{ if $icon }} +{{- /* Avoid extra whitespace */ -}} +{{- /* https://discourse.gohugo.io/t/55399/5 */ -}} +{{- $icon := resources.Get (printf "icons/%s.svg" ($.Get 0)) -}} +{{- if $icon -}} - {{ $icon.Content | safeHTML }} + {{- strings.Replace $icon.Content "\n" "" | safeHTML -}} -{{ else }} - {{ errorf `[BLOWFISH] Shortcode "icon" error in "%s": Resource "%s" not found. Check the path is correct or remove the shortcode.` .Page.Path (printf "icons/%s.svg" ($.Get 0)) }} -{{ end }} +{{- else -}} + {{- errorf `icon shortcode: resource "%s" not found. Check the path is correct or remove the shortcode: %s` (printf "icons/%s.svg" ($.Get 0)) .Position -}} +{{- end -}}