Skip to content

Commit 51e1261

Browse files
committed
Icon: Moved icon replacement code to partial
1 parent d9ded07 commit 51e1261

File tree

2 files changed

+56
-53
lines changed

2 files changed

+56
-53
lines changed

layouts/_default/docs.html

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,8 @@
55
{{ partial "sidebar.html" . }}
66
</nav>
77

8-
{{$content := .Content}}
9-
{{$pattern := `<i[^>]*class=["'][^"']*(?:fas?|fa-solid|fa-regular|fa-brands|far)\s+fa-([^"'\s]+)[^"']*["'][^>]*?(?:\s+style=["']([^"']*)["'])?[^>]*></i>`}}
10-
{{$matches := findRE $pattern $content}}
11-
12-
{{range $matches}}
13-
{{$currentMatch := .}}
14-
{{$iconName := ""}}
15-
{{$styleAttr := ""}}
16-
17-
{{$submatches := findRESubmatch $pattern $currentMatch}}
18-
{{if gt (len $submatches) 0}}
19-
{{$iconName = index (index $submatches 0) 1}}
20-
{{$styleAttr = index (index $submatches 0) 2}}
21-
22-
{{- $iconMappings := dict
23-
"bug-slash" "bug-off"
24-
"circle-info" "info"
25-
"info-circle" "info"
26-
"file-circle-plus" "file-plus"
27-
"check-circle" "circle-check"
28-
"heartbeat" "heart-pulse"
29-
"code-branch" "git-branch"
30-
"desktop" "monitor"
31-
"certificate" "badge"
32-
"cogs" "cog"
33-
"shield-alt" "shield-half"
34-
"memory" "cpu"
35-
"hdd" "hard-drive"
36-
"exclamation-triangle" "triangle-alert"
37-
"triangle-exclamation" "triangle-alert"
38-
"tachometer-alt" "circle-gauge"
39-
"circle-exclamation" "circle-alert"
40-
"arrow-up-right-from-square" "external-link"
41-
"pen-to-square" "square-pen"
42-
"flask" "flask-conical"
43-
-}}
44-
45-
{{ with index $iconMappings $iconName }}
46-
{{$iconName = .}}
47-
{{ end }}
48-
49-
{{$iconHTML := partial "lucide" (dict
50-
"context" $
51-
"icon" $iconName
52-
"style" $styleAttr
53-
)}}
54-
55-
{{ $modifiedMatch := replaceRE `>` ` data-mf=false>` $currentMatch 1}}
56-
{{ $modifiedMFIcon := printf "%s %s" $modifiedMatch $iconHTML }}
57-
{{$content = replace $content $currentMatch $modifiedMFIcon}}
58-
59-
{{end}}
60-
{{end}}
8+
<!-- Replace icons -->
9+
{{ $content := partial "icon-replacement.html" (dict "content" .Content) }}
6110

6211
{{if (.Params.catalog) }}
6312
<main class="content content-has-toc" role="main">
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{{ $content := .content }}
2+
{{ $pattern := `<i[^>]*class=["'][^"']*(?:fas?|fa-solid|fa-regular|fa-brands|far)\s+fa-([^"'\s]+)[^"']*["'][^>]*?(?:\s+style=["']([^"']*)["'])?[^>]*></i>` }}
3+
{{ $matches := findRE $pattern $content }}
4+
5+
{{range $matches}}
6+
{{$currentMatch := .}}
7+
{{$iconName := ""}}
8+
{{$styleAttr := ""}}
9+
10+
{{$submatches := findRESubmatch $pattern $currentMatch}}
11+
{{if gt (len $submatches) 0}}
12+
{{$iconName = index (index $submatches 0) 1}}
13+
{{$styleAttr = index (index $submatches 0) 2}}
14+
15+
{{- $iconMappings := dict
16+
"bug-slash" "bug-off"
17+
"circle-info" "info"
18+
"info-circle" "info"
19+
"file-circle-plus" "file-plus"
20+
"check-circle" "circle-check"
21+
"heartbeat" "heart-pulse"
22+
"code-branch" "git-branch"
23+
"desktop" "monitor"
24+
"certificate" "badge"
25+
"cogs" "cog"
26+
"shield-alt" "shield-half"
27+
"memory" "cpu"
28+
"hdd" "hard-drive"
29+
"exclamation-triangle" "triangle-alert"
30+
"triangle-exclamation" "triangle-alert"
31+
"tachometer-alt" "circle-gauge"
32+
"circle-exclamation" "circle-alert"
33+
"arrow-up-right-from-square" "external-link"
34+
"pen-to-square" "square-pen"
35+
"flask" "flask-conical"
36+
-}}
37+
38+
{{ with index $iconMappings $iconName }}
39+
{{$iconName = .}}
40+
{{ end }}
41+
42+
{{$iconHTML := partial "lucide" (dict
43+
"context" $
44+
"icon" $iconName
45+
"style" $styleAttr
46+
)}}
47+
48+
{{ $modifiedMatch := replaceRE `>` ` data-mf=false>` $currentMatch 1 }}
49+
{{ $modifiedMFIcon := printf "%s %s" $modifiedMatch $iconHTML }}
50+
{{ $content = replace $content $currentMatch $modifiedMFIcon }}
51+
{{end}}
52+
{{end}}
53+
54+
{{ return $content }}

0 commit comments

Comments
 (0)