Something went wrong. Try again.
version 2 of my website
Something went wrong. Try again.
1.2 kB · 43 lines
Astro
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344---import { ClientRouter } from "astro:transitions";
const { title } = Astro.props;const analyticsId = import.meta.env.ANALYTICS_ID;---
<head> <meta charset="utf-8" /> <link rel="icon" type="image/svg+xml" href="/favicon.ico" /> <meta name="viewport" content="width=device-width" /> <meta name="generator" content={Astro.generator} /> <title>{title}</title> <ClientRouter /> <script defer src="https://analytics.dustycode.dev/script.js" data-website-id={analyticsId}></script> <script> // Function to update theme function updateTheme() { if ( localStorage.theme === "dark" || (!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) ) { document.documentElement.classList.add("dark"); } else { document.documentElement.classList.remove("dark"); } }
// Run on page load updateTheme();
document.addEventListener("astro:after-swap", updateTheme);
// Listen for system theme changes window .matchMedia("(prefers-color-scheme: dark)") .addEventListener("change", updateTheme); </script></head>