From db7a34e975de8068d02bdc4a769761c91d48f193 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 27 Mar 2025 14:51:14 -0700 Subject: [PATCH] feat: enable dark theme and theme switcher --- astro.config.mjs | 5 +- src/components/ThemeProvider.astro | 38 ++- src/components/ThemeSelect.astro | 0 src/styles/style.css | 10 + src/styles/theme-dark.json | 425 +++++++++++++++++++++++++++++ 5 files changed, 475 insertions(+), 3 deletions(-) delete mode 100644 src/components/ThemeSelect.astro create mode 100644 src/styles/theme-dark.json diff --git a/astro.config.mjs b/astro.config.mjs index 1266a06..dc7ebb2 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -2,17 +2,18 @@ import { defineConfig } from 'astro/config'; import starlight from "@astrojs/starlight"; import { ExpressiveCodeTheme } from "@astrojs/starlight/expressive-code" import themeJson from "./src/styles/theme.json" +import darkThemeJson from "./src/styles/theme-dark.json" import { navigation } from "./src/components/navigation.ts"; const sakuraDreams = ExpressiveCodeTheme.fromJSONString(JSON.stringify(themeJson)); +const sakuraDreamsDark = ExpressiveCodeTheme.fromJSONString(JSON.stringify(darkThemeJson)); export default defineConfig({ site: "https://docs.nhcarrigan.com", integrations: [starlight({ components: { Footer: "./src/components/Footer.astro", - ThemeSelect: "./src/components/ThemeSelect.astro", ThemeProvider: "./src/components/ThemeProvider.astro", }, title: "NHCarrigan Docs", @@ -69,7 +70,7 @@ export default defineConfig({ "./src/fonts/font-face.css" ], expressiveCode: { - themes: [sakuraDreams] + themes: [sakuraDreams, sakuraDreamsDark], } }), ] diff --git a/src/components/ThemeProvider.astro b/src/components/ThemeProvider.astro index 7b69c65..b5330ae 100644 --- a/src/components/ThemeProvider.astro +++ b/src/components/ThemeProvider.astro @@ -1,6 +1,42 @@ +--- +import { Icon } from "@astrojs/starlight/components"; +--- + +{/* This is intentionally inlined to avoid FOUC. */} + +