From 59ec5cc4e203d1ed720d1b03144b664af4820f56 Mon Sep 17 00:00:00 2001 From: nemanjam Date: Wed, 21 Aug 2024 22:11:22 +0200 Subject: [PATCH] refactor theme and mode in progress --- docs/working-notes/todo3.md | 3 + src/components/Giscus.astro | 4 +- src/components/ThemeScript.astro | 56 +++++++++++------- src/components/ThemeToggle.astro | 4 +- src/config.ts | 2 + src/constants/{themes.ts => theme.ts} | 12 ++-- src/pages/links.astro | 4 +- src/schemas/config.ts | 5 ++ src/types/constants.ts | 2 +- src/utils/dom.ts | 35 +---------- src/utils/theme.ts | 85 +++++++++++++++++++++++++++ 11 files changed, 141 insertions(+), 71 deletions(-) rename src/constants/{themes.ts => theme.ts} (81%) create mode 100644 src/utils/theme.ts diff --git a/docs/working-notes/todo3.md b/docs/working-notes/todo3.md index b793798..84d069e 100644 --- a/docs/working-notes/todo3.md +++ b/docs/working-notes/todo3.md @@ -505,5 +505,8 @@ a href open in new tab fix links page links color for history back view transition refactor theme script, osDefaultMode, appDefaultMode, storedMode +change meta theme bg color with js, astro-paper + +replace import config with import.meta.env.VAR ------------ ``` diff --git a/src/components/Giscus.astro b/src/components/Giscus.astro index dc0abac..d7ca991 100644 --- a/src/components/Giscus.astro +++ b/src/components/Giscus.astro @@ -34,8 +34,8 @@ const { class: className } = Astro.props; import 'giscus'; import { SELECTORS } from '@/constants/dom'; - import { THEME_CONFIG } from '@/constants/themes'; - import { getCurrentMode, sendModeToGiscus } from '@/utils/dom'; + import { THEME_CONFIG } from '@/constants/theme'; + import { getCurrentMode, sendModeToGiscus } from '@/utils/theme'; import type { ChangeThemeCustomEvent } from '@/types/constants'; diff --git a/src/components/ThemeScript.astro b/src/components/ThemeScript.astro index 6a83aeb..c2d9486 100644 --- a/src/components/ThemeScript.astro +++ b/src/components/ThemeScript.astro @@ -1,24 +1,29 @@ --- -import * as themeConstants from '@/constants/themes'; +import * as themeConstants from '@/constants/theme'; +import { getDefaultThemes } from '@/utils/theme'; + +const defaultThemes = getDefaultThemes(); --- {/* Inlined to avoid flash of white content. */} - diff --git a/src/components/ThemeToggle.astro b/src/components/ThemeToggle.astro index b42f2d8..492248a 100644 --- a/src/components/ThemeToggle.astro +++ b/src/components/ThemeToggle.astro @@ -10,8 +10,8 @@ import { Icon } from 'astro-icon/components';