From 4502fe43ad4b2bee4b48c920d35c697b56c1fcb9 Mon Sep 17 00:00:00 2001 From: Darius Cepulis Date: Wed, 22 Oct 2025 10:32:35 -0700 Subject: [PATCH] feat(website): init dark mode --- eslint.config.mjs | 2 + website/TODO.md | 1 - website/astro.config.mjs | 1 + website/src/components/ClientCode.tsx | 10 +- website/src/components/Footer.astro | 76 ++++++----- website/src/components/FooterEasterEgg.astro | 2 +- website/src/components/NavBar/NavBar.astro | 4 +- website/src/components/Select.tsx | 8 +- website/src/components/ThemeInit.astro | 26 ++++ website/src/components/ThemeToggle.tsx | 118 ++++++++++++++++++ website/src/components/ToggleGroup.tsx | 4 +- website/src/components/Tooltip.tsx | 4 +- .../src/components/blog/AuthorSocialLinks.tsx | 4 +- .../src/components/blog/BlogPostCard.astro | 6 +- .../src/components/docs/DocsNavigation.astro | 8 +- website/src/components/docs/DocsSidebar.astro | 3 +- website/src/components/docs/Selectors.tsx | 2 +- website/src/components/docs/SidebarItem.astro | 8 +- .../TableOfContents.desktop.tsx | 2 +- .../TableOfContents.mobile.tsx | 2 +- .../components/typography/MarkdownCode.astro | 8 +- website/src/components/typography/Pre.astro | 8 +- website/src/consts.ts | 1 + website/src/layouts/Base.astro | 7 +- website/src/layouts/Docs.astro | 2 +- website/src/pages/blog/[...page].astro | 2 +- website/src/pages/blog/[...slug].astro | 9 +- website/src/pages/blog/authors/[author].astro | 4 +- .../[framework]/style/[style]/[...slug].astro | 2 +- website/src/pages/index.astro | 16 ++- website/src/styles/globals.css | 22 ++-- 31 files changed, 280 insertions(+), 92 deletions(-) create mode 100644 website/src/components/ThemeInit.astro create mode 100644 website/src/components/ThemeToggle.tsx diff --git a/eslint.config.mjs b/eslint.config.mjs index 09fcb870..8efc234e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -26,7 +26,9 @@ export default antfu( '**/.vercel/', '**/dist/', '**/styles/vjs.css', + // some files that make eslint/prettier panic 'website/src/components/Posthog.astro', + 'website/src/components/ThemeInit.astro', ], plugins: { 'jsx-a11y': jsxA11y, diff --git a/website/TODO.md b/website/TODO.md index afbf9521..22d80790 100644 --- a/website/TODO.md +++ b/website/TODO.md @@ -8,5 +8,4 @@ not comprehensive. just the things I'm worried about forgetting - animations - docs features - copy code blocks -- dark mode - search diff --git a/website/astro.config.mjs b/website/astro.config.mjs index 536b8227..6d494ec0 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -36,6 +36,7 @@ export default defineConfig({ shikiConfig: { themes: { light: 'gruvbox-light-hard', + dark: 'gruvbox-dark-medium', }, // TODO shiki transformers }, diff --git a/website/src/components/ClientCode.tsx b/website/src/components/ClientCode.tsx index 4e44027e..390b9cd2 100644 --- a/website/src/components/ClientCode.tsx +++ b/website/src/components/ClientCode.tsx @@ -3,6 +3,7 @@ import clsx from 'clsx'; import { createHighlighter, hastToHtml } from 'shiki'; import html from 'shiki/langs/html.mjs'; import tsx from 'shiki/langs/tsx.mjs'; +import gruvboxDarkSoft from 'shiki/themes/gruvbox-dark-soft.mjs'; import gruvboxLightHard from 'shiki/themes/gruvbox-light-hard.mjs'; // If you try importing more than one island with ClientCode in it, @@ -12,7 +13,7 @@ import gruvboxLightHard from 'shiki/themes/gruvbox-light-hard.mjs'; // eslint-disable-next-line antfu/no-top-level-await const highlighter: Highlighter = await createHighlighter({ - themes: [gruvboxLightHard], + themes: [gruvboxLightHard, gruvboxDarkSoft], langs: [html, tsx], }); @@ -25,7 +26,10 @@ export interface ClientCodeProps { export default function ClientCode({ code, lang, className }: ClientCodeProps) { const hast = highlighter.codeToHast(code, { lang, - theme: 'gruvbox-light-hard', + themes: { + light: 'gruvbox-light-hard', + dark: 'gruvbox-dark-soft', + }, }); // shiki gives us a root > pre > code > text structure @@ -51,7 +55,7 @@ export default function ClientCode({ code, lang, className }: ClientCodeProps) { return (
       
-  
+