Skip to content

Commit

Permalink
Add support for Simple Icons (#117)
Browse files Browse the repository at this point in the history
* Replace JS use in feather icons with SVG

There's still JS for the toggle functionality, but no more Javascript to
refresh the icons.

* Add support for SimpleIcons

This is based on https://github.com/simple-icons/simple-icons-font,
release 13.3.0, with font and css copied in.

Since Feather Icons and Simple Icons differ in purpose and naming
scheme, old social icons still point to feather. To add simple icons,
just prefix their name with "simple", e.g.

    - name: "mastodon"
      icon: "simple:mastodon"
      url: "https://foo.social/@foo"

Resolves #69, #95, #49
  • Loading branch information
pgeorgi authored Jan 7, 2025
1 parent f497a54 commit f2baec7
Show file tree
Hide file tree
Showing 9 changed files with 6,369 additions and 30 deletions.
10 changes: 10 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,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;
}
6,327 changes: 6,327 additions & 0 deletions assets/css/simple-icons.css

Large diffs are not rendered by default.

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.
12 changes: 5 additions & 7 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<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>
{{- if hasPrefix $key.icon "simple:" -}}
<a class="soc" href="{{ $key.url }}" rel="me" title="{{ $key.name }}"><i class="si si-{{ substr $key.icon 7 }}"></i></a>
{{- else -}}
<a class="soc" href="{{ $key.url }}" rel="me" title="{{ $key.name }}">{{ template "feathericon" (dict "Icon" $key.icon "UseCDN" .Site.Params.useCDN) }}</a>
{{- end -}}
<a class="border"></a>
{{- end -}}
</div>
Expand All @@ -13,9 +17,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/feather-icons@4.29.2/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
17 changes: 12 additions & 5 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@

{{- 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 isset .Site.Params "social" -}}
{{- range $index, $key := .Site.Params.Social -}}
{{- if hasPrefix $key.icon "simple:" -}}
{{- if (.Site.Params.useCDN | default false) -}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simple-icons-font@v13/font/simple-icons.min.css" type="text/css">
{{- else -}}
<link rel="stylesheet" href="{{ (resources.Get "css/simple-icons.css" | fingerprint).Permalink }}" type="text/css">
{{- end -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- 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
Binary file added static/fonts/SimpleIcons.woff2
Binary file not shown.
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

0 comments on commit f2baec7

Please sign in to comment.