refactor(config): 统一缓存键命名并优化主题设置逻辑
- 将缓存键名从带版本后缀的形式统一为无版本后缀 - 更新主题设置与读取逻辑,使用配置中心的缓存键定义 - 修正语言检测时对中文标识的判断逻辑 - 优化页面脚本加载顺序,确保配置文件优先加载 - 调整主题显示文本的中英文切换条件判断表达式
This commit is contained in:
@@ -13,7 +13,7 @@ function getStoredLanguage() {
|
|||||||
|
|
||||||
// 公共方法:设置本地存储的主题设置
|
// 公共方法:设置本地存储的主题设置
|
||||||
function setStoredTheme(theme) {
|
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({
|
localStorage.setItem(cacheKey, JSON.stringify({
|
||||||
value: theme, time: new Date().getTime()
|
value: theme, time: new Date().getTime()
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ const SiteConfig = {
|
|||||||
|
|
||||||
// 通用缓存键与TTL(毫秒)
|
// 通用缓存键与TTL(毫秒)
|
||||||
cacheKeys: {
|
cacheKeys: {
|
||||||
github: { key: 'gh_data_v2', ttlMs: 36000000 },
|
github: { key: 'gh_data', ttlMs: 36000000 },
|
||||||
blog: { key: 'blog_data_v2', ttlMs: 3600000 },
|
blog: { key: 'blog_data', ttlMs: 3600000 },
|
||||||
theme: { key: 'theme_v2', ttlMs: 3600000 }
|
theme: { key: 'theme', ttlMs: 3600000 }
|
||||||
},
|
},
|
||||||
|
|
||||||
techStack: [
|
techStack: [
|
||||||
|
|||||||
8
me.html
8
me.html
@@ -465,7 +465,7 @@
|
|||||||
<video id="input-video" style="display:none"></video>
|
<video id="input-video" style="display:none"></video>
|
||||||
<div id="canvas-container"></div>
|
<div id="canvas-container"></div>
|
||||||
<div id="aurora-layer"></div>
|
<div id="aurora-layer"></div>
|
||||||
|
<script src="js/config.js?version=20251125"></script>
|
||||||
<script>
|
<script>
|
||||||
/**
|
/**
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
@@ -530,7 +530,7 @@
|
|||||||
* ============================================================================
|
* ============================================================================
|
||||||
*/
|
*/
|
||||||
function getStoredTheme() {
|
function getStoredTheme() {
|
||||||
const cacheKey = 'theme-v2';
|
const cacheKey = window.SiteConfig?.cacheKeys?.theme?.key || 'theme';
|
||||||
const cacheJson = localStorage.getItem(cacheKey);
|
const cacheJson = localStorage.getItem(cacheKey);
|
||||||
const saved = cacheJson ? JSON.parse(cacheJson) : null;
|
const saved = cacheJson ? JSON.parse(cacheJson) : null;
|
||||||
|
|
||||||
@@ -548,7 +548,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getStoredLanguage() {
|
function getStoredLanguage() {
|
||||||
return localStorage.getItem('lang') || (navigator.language.startsWith('zh') ? 'cn' : 'en');
|
return localStorage.getItem('lang') || (navigator.language.startsWith('zh') ? 'zh' : 'en');
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENV = {
|
const ENV = {
|
||||||
@@ -625,7 +625,7 @@
|
|||||||
// 应用主题
|
// 应用主题
|
||||||
document.documentElement.setAttribute('data-theme', ENV.theme);
|
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.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');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user