From e173b8a89e5768a7fd3abe1b4dadc078b9fbb077 Mon Sep 17 00:00:00 2001 From: Samidy Date: Sat, 20 Dec 2025 12:36:30 +0300 Subject: [PATCH] shitty (probably not working) fix for preset themes --- docs/.vitepress/theme/components/ColorPicker.vue | 10 ++++++++++ docs/.vitepress/theme/themes/themeHandler.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/.vitepress/theme/components/ColorPicker.vue b/docs/.vitepress/theme/components/ColorPicker.vue index efafa54ba..3d46364c9 100644 --- a/docs/.vitepress/theme/components/ColorPicker.vue +++ b/docs/.vitepress/theme/components/ColorPicker.vue @@ -205,6 +205,16 @@ watch(selectedColor, async (color) => { if (!color) return; const theme = generateThemeFromColor(color) themeRegistry[`color-${color}`] = theme + // Hopeful Fix For Preset Themes + try { + const key = 'vitepress-theme-data' + const raw = localStorage.getItem(key) + const parsed = raw ? JSON.parse(raw) as Record : {} + parsed[`color-${color}`] = theme + localStorage.setItem(key, JSON.stringify(parsed)) + } catch (e) { + // ignore storage errors + } // Explicitly set the theme to override any previous selection await nextTick() console.log('Setting theme to:', `color-${color}`) diff --git a/docs/.vitepress/theme/themes/themeHandler.ts b/docs/.vitepress/theme/themes/themeHandler.ts index 682f6c7f7..b644261e9 100644 --- a/docs/.vitepress/theme/themes/themeHandler.ts +++ b/docs/.vitepress/theme/themes/themeHandler.ts @@ -21,6 +21,7 @@ import { themeRegistry } from './configs' const STORAGE_KEY_THEME = 'vitepress-theme-name' const STORAGE_KEY_MODE = 'vitepress-display-mode' const STORAGE_KEY_AMOLED = 'vitepress-amoled-enabled' +const STORAGE_KEY_THEME_DATA = 'vitepress-theme-data' export class ThemeHandler { private state = ref({ @@ -46,6 +47,20 @@ export class ThemeHandler { if (themeRegistry[savedTheme]) { this.state.value.currentTheme = savedTheme this.state.value.theme = themeRegistry[savedTheme] + } else { + try { + const raw = localStorage.getItem(STORAGE_KEY_THEME_DATA) + if (raw) { + const parsed = JSON.parse(raw) as Record + if (parsed && parsed[savedTheme]) { + themeRegistry[savedTheme] = parsed[savedTheme] + this.state.value.currentTheme = savedTheme + this.state.value.theme = parsed[savedTheme] + } + } + } catch (e) { + // ignore parse errors + } } // Set amoled preference