mirror of
https://github.com/imfing/hextra.git
synced 2025-08-23 18:46:38 -04:00

* fix(favicon): dynamic favicon switching based on color scheme in js * refactor(favicon): simplify favicon logic and ensure dynamic switching based on color scheme * docs(favicon): enhance favicon setup instructions with dark mode support and adaptive SVG guidance
23 lines
741 B
JavaScript
23 lines
741 B
JavaScript
// {{ $faviconDarkExists := fileExists (path.Join "static" "favicon-dark.svg") }}
|
|
(function () {
|
|
const faviconEl = document.getElementById("favicon-svg");
|
|
const faviconDarkExists = "{{ $faviconDarkExists }}" === "true";
|
|
|
|
if (faviconEl && faviconDarkExists) {
|
|
const lightFavicon = '{{ "favicon.svg" | relURL }}';
|
|
const darkFavicon = '{{ "favicon-dark.svg" | relURL }}';
|
|
|
|
const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
|
|
function updateFavicon(e) {
|
|
faviconEl.href = e.matches ? darkFavicon : lightFavicon;
|
|
}
|
|
|
|
// Set favicon on load
|
|
updateFavicon(darkModeQuery);
|
|
|
|
// Listen for system preference changes
|
|
darkModeQuery.addEventListener("change", updateFavicon);
|
|
}
|
|
})();
|