Skip to content

Commit

Permalink
♻️ Refactor: icon plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Aug 29, 2024
1 parent 5aaacec commit 3b99838
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.10-5e1a7845" -}}
{{- .Scratch.Set "version" "v0.3.10-5aaacec0" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down
16 changes: 14 additions & 2 deletions layouts/partials/plugin/icon.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
{{- $prefix := $.Prefix | default "lib/simple-icons/icons" | strings.TrimSuffix "/" -}}
{{- $src = printf "%v/%v.svg" $prefix . -}}
{{- end -}}

{{ if not $src }}
{{- errorf "Icon src is missing" -}}
{{- end -}}

{{- if (urls.Parse $src).Host | not -}}
{{- $src = (resources.Get $src | minify).RelPermalink -}}
{{- $resource := resources.Get $src | minify -}}
{{ if not $resource }}
{{- errorf "Icon does not exist %v" $src -}}
{{- end -}}
{{- $resource := $resource.Content -}}
{{- $resource | replaceRE `<svg ` `<svg class="icon" ` | safeHTML -}}
{{- else -}}
{{- /* fetch svg icon from external source */ -}}
<i data-svg-src="{{ $src }}" aria-hidden="true"></i>
{{- end -}}
<i data-svg-src="{{ $src }}" aria-hidden="true"></i>
{{- end -}}

0 comments on commit 3b99838

Please sign in to comment.