2026-06-05 14:31:12 -06:00
|
|
|
---
|
|
|
|
|
//import "../global.css";
|
|
|
|
|
import Header from "../components/Header.astro";
|
|
|
|
|
import Footer from "../components/Footer.astro";
|
2026-08-10 14:59:05 -06:00
|
|
|
import Meta from "../components/Meta.astro";
|
2026-06-05 14:31:12 -06:00
|
|
|
|
|
|
|
|
import { urlfrag } from "../utils/path.js";
|
|
|
|
|
|
2026-08-10 14:59:05 -06:00
|
|
|
const { title, image } = Astro.props;
|
2026-06-05 14:31:12 -06:00
|
|
|
const base = import.meta.env.BASE_URL;
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<!doctype html>
|
2026-11-24 14:29:42 -07:00
|
|
|
<html lang="en">
|
2026-06-05 14:31:12 -06:00
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2026-08-06 10:30:42 -06:00
|
|
|
<meta name="theme-color" content="#28303c" />
|
2026-08-10 14:59:05 -06:00
|
|
|
<Meta title={title} image={image} />
|
2026-06-05 14:31:12 -06:00
|
|
|
<link rel="icon" type="image/svg+xml" href={urlfrag(base, 'favicon.svg')} />
|
|
|
|
|
<link rel="icon" href={urlfrag(base, 'favicon.png')} />
|
|
|
|
|
<title>{title}</title>
|
2026-11-24 14:29:42 -07:00
|
|
|
<script>
|
2026-06-23 17:26:11 -06:00
|
|
|
function hasLocalStorage() {
|
|
|
|
|
try {
|
|
|
|
|
var ls = localStorage;
|
|
|
|
|
var key = "__test";
|
|
|
|
|
ls.setItem(key, key);
|
|
|
|
|
ls.removeItem(key);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return (
|
|
|
|
|
e instanceof DOMException &&
|
|
|
|
|
e.name === "QuotaExceededError" &&
|
|
|
|
|
localStorage &&
|
|
|
|
|
localStorage.length !== 0
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-22 15:03:55 -06:00
|
|
|
|
2026-06-22 23:55:36 -06:00
|
|
|
class ThemeToggler {
|
|
|
|
|
elements: NodeListOf<Element>;
|
2026-11-24 14:29:42 -07:00
|
|
|
btnThemeState: string = 'light';
|
|
|
|
|
exclude: string[] = ['df'];
|
|
|
|
|
ls: boolean = false;
|
2026-06-22 23:55:36 -06:00
|
|
|
|
|
|
|
|
constructor() {
|
2026-11-24 14:29:42 -07:00
|
|
|
this.ls = hasLocalStorage();
|
|
|
|
|
this.toggleThemeClass();
|
|
|
|
|
if (this.ls && ('theme' in localStorage && localStorage.theme !== 'undefined')) {
|
|
|
|
|
this.btnThemeState = localStorage.theme;
|
2026-06-23 16:58:57 -06:00
|
|
|
} else {
|
2026-11-24 14:29:42 -07:00
|
|
|
this.btnThemeState = 'system';
|
2026-06-22 23:55:36 -06:00
|
|
|
}
|
|
|
|
|
this.elements = document.querySelectorAll('[data-toggle-theme]');
|
|
|
|
|
this.elements.forEach((e) => {
|
2026-11-24 14:29:42 -07:00
|
|
|
this.setThemeState(e, this.btnThemeState);
|
2026-06-22 23:55:36 -06:00
|
|
|
e.addEventListener('click', this);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleEvent() {
|
|
|
|
|
const state = localStorage.theme;
|
|
|
|
|
this.elements.forEach((e) => {
|
2026-11-24 14:29:42 -07:00
|
|
|
this.setNextTheme(e, state);
|
|
|
|
|
const s = this.getThemeState(e);
|
2026-06-22 23:55:36 -06:00
|
|
|
if (s != localStorage.theme) {
|
2026-11-24 14:29:42 -07:00
|
|
|
localStorage.theme = this.getThemeState(e);
|
2026-06-22 23:55:36 -06:00
|
|
|
}
|
|
|
|
|
});
|
2026-11-24 14:29:42 -07:00
|
|
|
this.toggleThemeClass();
|
2026-06-22 23:55:36 -06:00
|
|
|
}
|
|
|
|
|
|
2026-11-24 14:29:42 -07:00
|
|
|
getThemeState(element: Element): string {
|
2026-06-22 23:55:36 -06:00
|
|
|
const attr = element.getAttribute('data-toggle-theme');
|
|
|
|
|
return attr != null ? attr : 'light';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSysTheme(): string {
|
|
|
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-24 14:29:42 -07:00
|
|
|
setThemeState(element: Element, state: string) {
|
2026-06-22 23:55:36 -06:00
|
|
|
element.setAttribute('data-toggle-theme', state);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-24 14:29:42 -07:00
|
|
|
setNextTheme(element: Element, state: string) {
|
2026-06-22 23:55:36 -06:00
|
|
|
const states = ['light', 'dark', 'system'];
|
|
|
|
|
let next = states.indexOf(state) + 1;
|
|
|
|
|
if (next === states.length) {
|
|
|
|
|
next = 0;
|
|
|
|
|
}
|
|
|
|
|
element.setAttribute('data-toggle-theme', states[next]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sysTheme(): string {
|
|
|
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-24 14:29:42 -07:00
|
|
|
toggleThemeClass() {
|
2026-06-22 23:55:36 -06:00
|
|
|
const ele = document.documentElement;
|
2026-11-24 14:29:42 -07:00
|
|
|
for (const e of this.exclude) {
|
|
|
|
|
if (ele.classList.contains(e)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-25 23:01:18 -07:00
|
|
|
if (localStorage.af_enabled === '1') {
|
|
|
|
|
if (localStorage.af_mode === 'df') {
|
|
|
|
|
ele.classList.remove('dark');
|
|
|
|
|
ele.classList.add('df');
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-06-22 23:55:36 -06:00
|
|
|
switch (localStorage.theme) {
|
|
|
|
|
case 'light':
|
|
|
|
|
ele.classList.remove('dark');
|
|
|
|
|
break;
|
|
|
|
|
case 'dark':
|
|
|
|
|
ele.classList.add('dark');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ele.classList.toggle('dark', this.getSysTheme() === 'dark');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new ThemeToggler();
|
2026-06-22 15:03:55 -06:00
|
|
|
</script>
|
2026-06-05 14:31:12 -06:00
|
|
|
</head>
|
|
|
|
|
<body class="flex flex-col min-h-screen">
|
|
|
|
|
<Header />
|
|
|
|
|
<main class="grow">
|
|
|
|
|
<slot />
|
|
|
|
|
</main>
|
|
|
|
|
<Footer />
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|