From 62aa324e16e24ff31b3f40673045294e88a197bc Mon Sep 17 00:00:00 2001 From: Daisuke Date: Wed, 11 Feb 2026 13:15:03 +0900 Subject: [PATCH] feat: implement dark mode support - Introduce CSS variables for theming in `global.css` - Add `ThemeIcon` component for toggling light/dark modes - Integrate theme initialization script in `BaseLayout` to prevent FOUC - Update navigation, buttons, and tag styles for dark mode compatibility - Configure Shiki for dual-theme syntax highlighting in `astro.config.mjs` - Adjust link colors to accessible blue shades for both themes --- astro.config.mjs | 11 ++- src/components/BlogPost.astro | 10 ++- src/components/Header.astro | 8 +++ src/components/Navigation.astro | 3 +- src/components/ThemeIcon.astro | 36 ++++++++++ src/layouts/BaseLayout.astro | 16 +++++ src/layouts/MarkdownPostLayout.astro | 11 ++- src/pages/blog/[...page].astro | 13 ++++ src/pages/index.astro | 104 ++++++++++++++------------- src/pages/tags/index.astro | 11 ++- src/styles/global.css | 56 ++++++++++++--- 11 files changed, 218 insertions(+), 61 deletions(-) create mode 100644 src/components/ThemeIcon.astro diff --git a/astro.config.mjs b/astro.config.mjs index 87c4c0f..dde729c 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -6,5 +6,14 @@ import preact from "@astrojs/preact"; // https://astro.build/config export default defineConfig({ site: "https://blog.n-daisuke897.com/", - integrations: [preact()] + integrations: [preact()], + markdown: { + shikiConfig: { + themes: { + light: 'github-light', + dark: 'github-dark', + }, + wrap: true, + }, + }, }); \ No newline at end of file diff --git a/src/components/BlogPost.astro b/src/components/BlogPost.astro index e10aa0b..32cfb32 100644 --- a/src/components/BlogPost.astro +++ b/src/components/BlogPost.astro @@ -12,11 +12,19 @@ const { title, url, datetime } = Astro.props; font-size: 14px; color: #666; } + :global(.dark) .new-article-date { + color: #94a3b8; + } .new-article-title { font-size: 18px; font-weight: bold; - color: #333f; + color: var(--text-color); + text-decoration: none; } + .new-article-title:hover { + text-decoration: underline; + } + /* Removed specific dark mode color to inherit var(--text-color) */
diff --git a/src/components/Header.astro b/src/components/Header.astro index b058c25..bd43431 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -9,3 +9,11 @@ import Navigation from "./Navigation.astro"; + + diff --git a/src/components/Navigation.astro b/src/components/Navigation.astro index 67284b2..fe72b60 100644 --- a/src/components/Navigation.astro +++ b/src/components/Navigation.astro @@ -1,8 +1,9 @@ --- - +import ThemeIcon from "./ThemeIcon.astro"; ---