Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace JS use in feather icons with SVG #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,13 @@ table td{
padding: 6px 13px;
border: 1px solid #dfe2e5;
}

.feather {
width: 24px;
height: 24px;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
fill: none;
}
1 change: 1 addition & 0 deletions assets/svg/feather-sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 1 addition & 7 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<footer>
<div style="display:flex">
{{- range $index, $key := .Site.Params.Social -}}
<a class="soc" href="{{ $key.url }}" rel="me" title="{{ $key.name }}"><i data-feather="{{ $key.icon }}"></i></a>
<a class="soc" href="{{ $key.url }}" rel="me" title="{{ $key.name }}">{{ template "feathericon" (dict "Icon" $key.icon "UseCDN" .Site.Params.useCDN) }}</a>
<a class="border"></a>
{{- end -}}
</div>
Expand All @@ -13,9 +13,3 @@
{{ if not hugo.IsServer }}
{{ template "_internal/google_analytics.html" . }}
{{ end }}

{{- if (isset .Site.Params "social") -}}
<script>
feather.replace()
</script>
{{- end -}}
12 changes: 11 additions & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{{- define "feathericon" -}}
{{- $featherURL := "https://unpkg.com/[email protected]/dist/feather-sprite.svg" -}}
{{ if not (.UseCDN | default false) -}}
{{- $featherURL = (resources.Get "svg/feather-sprite.svg" | fingerprint).RelPermalink -}}
{{- end -}}
<svg class="feather">
<use href="{{ printf "%s#%s" $featherURL .Icon }}" />
</svg>
{{- end -}}

<header>
<div class="main">
<a href="{{ absURL "/" }}">{{ .Site.Title }}</a>
Expand All @@ -7,7 +17,7 @@
<a href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
{{ if eq .Site.Params.mode "toggle" -}}
| <span id="dark-mode-toggle" onclick="toggleTheme()"></span>
| <span id="dark-mode-toggle" onclick="toggleTheme()">{{template "feathericon" (dict "UseCDN" .Site.Params.useCDN "Icon" "sun") }}</span>
<script src="{{ absURL "js/themetoggle.js" }}"></script>
{{ end }}
</nav>
Expand Down
5 changes: 0 additions & 5 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/twitter_cards.html" . -}}
{{ if and (isset .Site.Params "social") (.Site.Params.useCDN | default false) -}}
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
{{- else if or (isset .Site.Params "social") (eq .Site.Params.mode "toggle") -}}
<script src="{{ absURL "js/feather.min.js" }}"></script>
{{ end }}
{{ if .Site.Params.useCDN | default false -}}
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@1,500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap" rel="stylesheet">
Expand Down
13 changes: 0 additions & 13 deletions static/js/feather.min.js

This file was deleted.

7 changes: 3 additions & 4 deletions static/js/themetoggle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
function setTheme(mode) {
localStorage.setItem("theme-storage", mode);
var e = document.querySelector("#dark-mode-toggle > .feather > use")
if (mode === "dark") {
document.getElementById("darkModeStyle").disabled=false;
document.getElementById("dark-mode-toggle").innerHTML = "<i data-feather=\"sun\"></i>";
feather.replace()
e.href.baseVal = e.href.baseVal.replace(/#.*$/, "#sun")
} else if (mode === "light") {
document.getElementById("darkModeStyle").disabled=true;
document.getElementById("dark-mode-toggle").innerHTML = "<i data-feather=\"moon\"></i>";
feather.replace()
e.href.baseVal = e.href.baseVal.replace(/#.*$/, "#moon")
}
}

Expand Down