refactor(config): 统一缓存键命名并优化主题设置逻辑

- 将缓存键名从带版本后缀的形式统一为无版本后缀
- 更新主题设置与读取逻辑,使用配置中心的缓存键定义
- 修正语言检测时对中文标识的判断逻辑
- 优化页面脚本加载顺序,确保配置文件优先加载
- 调整主题显示文本的中英文切换条件判断表达式
This commit is contained in:
hehh
2025-12-04 19:30:57 +08:00
parent 0174d29bde
commit 978b618df2
3 changed files with 8 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ function getStoredLanguage() {
// 公共方法:设置本地存储的主题设置
function setStoredTheme(theme) {
const cacheKey = window.SiteConfig?.cacheKeys?.theme?.key || 'theme-v2';
const cacheKey = window.SiteConfig?.cacheKeys?.theme?.key || 'theme';
localStorage.setItem(cacheKey, JSON.stringify({
value: theme, time: new Date().getTime()
}));

View File

@@ -43,9 +43,9 @@ const SiteConfig = {
// 通用缓存键与TTL毫秒
cacheKeys: {
github: { key: 'gh_data_v2', ttlMs: 36000000 },
blog: { key: 'blog_data_v2', ttlMs: 3600000 },
theme: { key: 'theme_v2', ttlMs: 3600000 }
github: { key: 'gh_data', ttlMs: 36000000 },
blog: { key: 'blog_data', ttlMs: 3600000 },
theme: { key: 'theme', ttlMs: 3600000 }
},
techStack: [

View File

@@ -465,7 +465,7 @@
<video id="input-video" style="display:none"></video>
<div id="canvas-container"></div>
<div id="aurora-layer"></div>
<script src="js/config.js?version=20251125"></script>
<script>
/**
* ============================================================================
@@ -530,7 +530,7 @@
* ============================================================================
*/
function getStoredTheme() {
const cacheKey = 'theme-v2';
const cacheKey = window.SiteConfig?.cacheKeys?.theme?.key || 'theme';
const cacheJson = localStorage.getItem(cacheKey);
const saved = cacheJson ? JSON.parse(cacheJson) : null;
@@ -548,7 +548,7 @@
}
function getStoredLanguage() {
return localStorage.getItem('lang') || (navigator.language.startsWith('zh') ? 'cn' : 'en');
return localStorage.getItem('lang') || (navigator.language.startsWith('zh') ? 'zh' : 'en');
}
const ENV = {
@@ -625,7 +625,7 @@
// 应用主题
document.documentElement.setAttribute('data-theme', ENV.theme);
safeUpdateText(DOM_CACHE.themeDisplay, `THEME: ${ENV.lang.toUpperCase() === 'en' ? ENV.theme.toUpperCase() : ENV.theme === 'day' ? '白天' : '黑夜'}`);
safeUpdateText(DOM_CACHE.langDisplay, ENV.lang.toUpperCase() === 'CN' ? '中文' : 'English');
safeUpdateText(DOM_CACHE.langDisplay, ENV.lang.toUpperCase() === 'ZH' ? '中文' : 'English');
/**
* ============================================================================