mirror of https://github.com/VERT-sh/VERT.git
parent
8ea970a495
commit
7c0f2c87d1
|
@ -115,8 +115,19 @@
|
||||||
// Apply theme before DOM is loaded
|
// Apply theme before DOM is loaded
|
||||||
let theme = localStorage.getItem("theme");
|
let theme = localStorage.getItem("theme");
|
||||||
if (theme !== "light" && theme !== "dark") {
|
if (theme !== "light" && theme !== "dark") {
|
||||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
const prefersDark = window.matchMedia(
|
||||||
|
"(prefers-color-scheme: dark)",
|
||||||
|
).matches;
|
||||||
theme = prefersDark ? "dark" : "light";
|
theme = prefersDark ? "dark" : "light";
|
||||||
|
|
||||||
|
if (!theme) {
|
||||||
|
// first time visitor
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
window.plausible("Theme set", {
|
||||||
|
props: { theme: theme.dark ? "dark" : "light" },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.documentElement.classList.add(theme);
|
document.documentElement.classList.add(theme);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { browser } from "$app/environment";
|
import { browser } from "$app/environment";
|
||||||
import { theme } from "$lib/store/index.svelte";
|
|
||||||
|
|
||||||
export const load = ({ data }) => {
|
export const load = ({ data }) => {
|
||||||
if (!browser) return;
|
if (!browser) return;
|
||||||
|
@ -10,10 +9,6 @@ export const load = ({ data }) => {
|
||||||
status: 200,
|
status: 200,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
window.plausible("Theme set", {
|
|
||||||
props: { theme: theme.dark ? "dark" : "light" },
|
|
||||||
});
|
|
||||||
theme.dark = localStorage.getItem("theme") === "dark";
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue