Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wangchucheng/hugo-eureka.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWANG Chucheng <me@wangchucheng.com>2022-02-03 08:12:39 +0300
committerWANG Chucheng <me@wangchucheng.com>2022-02-03 08:12:39 +0300
commit89c48bd92b34b165770069b01aa9e2511d0448ca (patch)
tree37a7633d768f79cc9ac0fff66253a505a8467354 /layouts
parent72c35bec01c80baf75bcaf61b363ffe337ee7f2d (diff)
refactor: reduce Font Awesome size with tree shaking
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/head.html17
-rw-r--r--layouts/partials/utils/camelize.html8
-rw-r--r--layouts/partials/utils/get-fontawesome-icons.html56
-rw-r--r--layouts/partials/utils/get-js-configs.html2
4 files changed, 69 insertions, 14 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index a81c00c..7d98c8e 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -77,8 +77,10 @@
<script defer src="{{ printf $assets.highlightjs.languages.url $assets.highlightjs.version . }}"
{{ with $assets.highlightjs.languages.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
{{ end }}
-<script defer src="{{ printf $assets.fontawesome.js.url $assets.fontawesome.version }}"
- {{ with $assets.fontawesome.js.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
+
+{{ $fontawesomeJS := resources.Get "js/fontawesome.js" | resources.ExecuteAsTemplate "js/fontawesome.js" . | js.Build (dict "minify" true) | minify | fingerprint "sha384" }}
+<script defer type="text/javascript" src="{{ $fontawesomeJS.Permalink }}" integrity="{{ $fontawesomeJS.Data.Integrity }}"></script>
+
{{- $enableMath := false }}
{{- if .Site.Params.math.handler }}
@@ -96,17 +98,6 @@
{{- end }}
{{- end }}
-{{ define "partials/camelize" }}
-{{ $input := . }}
-{{ $regexp := "(-|_)([a-z])" }}
-{{ $matches := findRE $regexp $input }}
-{{ range $matches }}
- {{ $input = $input | replaceRE . (upper .) }}
-{{ end }}
-{{ $input = $input | replaceRE "(-|_)" "" }}
-{{ return $input }}
-{{ end }}
-
{{/* KaTeX */}}
{{- if and (eq .Site.Params.math.handler "katex") $enableMath }}
<link rel="stylesheet" href="{{ printf $assets.katex.css.url $assets.katex.version }}"
diff --git a/layouts/partials/utils/camelize.html b/layouts/partials/utils/camelize.html
new file mode 100644
index 0000000..bb3afa9
--- /dev/null
+++ b/layouts/partials/utils/camelize.html
@@ -0,0 +1,8 @@
+{{ $input := . }}
+{{ $regexp := "(-|_)([a-z])" }}
+{{ $matches := findRE $regexp $input }}
+{{ range $matches }}
+ {{ $input = $input | replaceRE . (upper .) }}
+{{ end }}
+{{ $input = $input | replaceRE "(-|_)" "" }}
+{{ return $input }} \ No newline at end of file
diff --git a/layouts/partials/utils/get-fontawesome-icons.html b/layouts/partials/utils/get-fontawesome-icons.html
new file mode 100644
index 0000000..3fbf331
--- /dev/null
+++ b/layouts/partials/utils/get-fontawesome-icons.html
@@ -0,0 +1,56 @@
+{{ $fasIcons := slice }}
+{{ $fabIcons := slice }}
+{{ $farIcons := slice }}
+
+{{/* eureka */}}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-adjust") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-bars") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-calendar") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-caret-down") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-caret-left") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-caret-right") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-clock") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-edit") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-folder") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-globe") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-moon") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-sun") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-th-list") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-user") }}
+{{ $fasIcons = $fasIcons | append (partial "utils/camelize" "fa-user-circle") }}
+
+{{/* authors */}}
+{{ range (.Site.GetPage "taxonomyTerm" "authors").Pages }}
+ {{ range .Params.social }}
+ {{ $icon := partial "utils/camelize" (print "fa-" .icon) }}
+ {{ if and (eq .iconPack "fas") (not (in $fasIcons $icon)) }}
+ {{ $fasIcons = $fasIcons | append $icon }}
+ {{ else if and (eq .iconPack "fab") (not (in $fabIcons $icon)) }}
+ {{ $fabIcons = $fabIcons | append $icon }}
+ {{ else if and (eq .iconPack "far") (not (in $farIcons $icon)) }}
+ {{ $farIcons = $farIcons | append $icon }}
+ {{ end }}
+ {{ end }}
+{{ end }}
+
+{{/* homepage.about */}}
+{{ $homepage := .Site.GetPage "homepage" }}
+{{ $widgets := $homepage.Resources }}
+{{ range $widgets }}
+ {{ if eq .Params.widget.handler "about" }}
+ {{ range .Params.social }}
+ {{ $icon := partial "utils/camelize" (print "fa-" .icon) }}
+ {{ if and (eq .iconPack "fas") (not (in $fasIcons $icon)) }}
+ {{ $fasIcons = $fasIcons | append $icon }}
+ {{ else if and (eq .iconPack "fab") (not (in $fabIcons $icon)) }}
+ {{ $fabIcons = $fabIcons | append $icon }}
+ {{ else if and (eq .iconPack "far") (not (in $farIcons $icon)) }}
+ {{ $farIcons = $farIcons | append $icon }}
+ {{ end }}
+ {{ end }}
+ {{ end }}
+{{ end }}
+
+{{ $icons := dict "fas" $fasIcons "fab" $fabIcons "far" $farIcons }}
+
+{{ return $icons }}
diff --git a/layouts/partials/utils/get-js-configs.html b/layouts/partials/utils/get-js-configs.html
index bb45a25..7198692 100644
--- a/layouts/partials/utils/get-js-configs.html
+++ b/layouts/partials/utils/get-js-configs.html
@@ -1,6 +1,6 @@
{{- range $key, $value := . }}
{{- if or $value (eq $value false) }}
- {{- $key = partial "partials/camelize" $key }}
+ {{- $key = partial "utils/camelize" $key }}
{{- $key }}:
{{- if reflect.IsMap $value }}
{