mirror of https://github.com/jpanther/congo.git
🔀 Merge pull request #379 from jpanther/theme-color
💄 Add support for `theme-color` meta tag
pull/383/head
commit
88817a5bde
|
@ -1,8 +1,22 @@
|
||||||
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
|
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
|
||||||
const userPreference = localStorage.getItem("appearance");
|
const userPreference = localStorage.getItem("appearance");
|
||||||
|
|
||||||
|
function getCSSValue(varName) {
|
||||||
|
var cssValue = window.getComputedStyle(document.documentElement).getPropertyValue(varName);
|
||||||
|
return "rgb(" + cssValue.replace(/\s+/g, "") + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
function setThemeColor() {
|
||||||
|
var metaThemeColor = document.querySelector("meta[name=theme-color]");
|
||||||
|
document.documentElement.classList.contains("dark")
|
||||||
|
? metaThemeColor.setAttribute("content", getCSSValue("--color-neutral-800"))
|
||||||
|
: metaThemeColor.setAttribute("content", getCSSValue("--color-neutral"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {
|
if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {
|
||||||
document.documentElement.classList.add("dark");
|
document.documentElement.classList.add("dark");
|
||||||
|
setThemeColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
||||||
|
@ -12,6 +26,7 @@ if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
||||||
userPreference !== "light"
|
userPreference !== "light"
|
||||||
) {
|
) {
|
||||||
document.documentElement.classList.add("dark");
|
document.documentElement.classList.add("dark");
|
||||||
|
setThemeColor();
|
||||||
}
|
}
|
||||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
|
||||||
if (event.matches) {
|
if (event.matches) {
|
||||||
|
@ -19,6 +34,7 @@ if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
||||||
} else {
|
} else {
|
||||||
document.documentElement.classList.remove("dark");
|
document.documentElement.classList.remove("dark");
|
||||||
}
|
}
|
||||||
|
setThemeColor();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +43,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
if (switcher) {
|
if (switcher) {
|
||||||
switcher.addEventListener("click", () => {
|
switcher.addEventListener("click", () => {
|
||||||
document.documentElement.classList.toggle("dark");
|
document.documentElement.classList.toggle("dark");
|
||||||
|
setThemeColor();
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
"appearance",
|
"appearance",
|
||||||
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<meta http-equiv="content-language" content="{{ . }}" />
|
<meta http-equiv="content-language" content="{{ . }}" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="theme-color" content="rgb(255,255,255)" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||||
{{/* Title */}}
|
{{/* Title */}}
|
||||||
{{ if .IsHome -}}
|
{{ if .IsHome -}}
|
||||||
|
|
Loading…
Reference in New Issue