refactor(config): 重构站点配置加载逻辑

- 将SiteConfig封装为IIFE避免全局污染
- 移除about.html中的内联SiteConfig定义
- 统一通过js/config.js管理所有配置项
- 修复统计脚本加载时对SiteConfig的依赖问题
- 确保配置在模块化和浏览器环境中正常导出
- 优化不蒜子统计ID获取方式提升容错性
This commit is contained in:
hehh
2025-12-12 12:06:49 +08:00
parent e47c5c2803
commit 2b6d363aba
2 changed files with 165 additions and 208 deletions

View File

@@ -109,51 +109,6 @@
<script> <script>
if (/*@cc_on!@*/false || (!!window.MSInputMethodContext && !!document.documentMode)) window.location.href = "https://imsyy.top/upgrade-your-browser/index.html?referrer=" + encodeURIComponent(window.location.href); if (/*@cc_on!@*/false || (!!window.MSInputMethodContext && !!document.documentMode)) window.location.href = "https://imsyy.top/upgrade-your-browser/index.html?referrer=" + encodeURIComponent(window.location.href);
</script> </script>
<!-- 关键JS内联 -->
<script>
// 预加载关键配置
const SiteConfig = {
github: { username: 'listener-He' },
blog: { rssUrl: 'https://blog.hehouhui.cn/api/rss' },
cacheKeys: {
github: { key: 'gh_data', ttlMs: 36000000 },
blog: { key: 'blog_data', ttlMs: 3600000 },
theme: { key: 'theme', ttlMs: 3600000 }
},
analytics: {
busuanzi: {
src: '//cdn.busuanzi.cc/busuanzi/3.6.9/busuanzi.abbr.min.js',
site_pv_id: 'busuanzi_site_pv',
site_uv_id: 'busuanzi_site_uv'
},
baidu: { src: 'https://hm.baidu.com/hm.js?ae2a009a75b13c21d5121ee51375ea4e' },
tencent: { id: '3OBGjwDdEIRS7XZ1', ck: '3OBGjwDdEIRS7XZ1' }
},
artalk: {
server: 'https://artalk.hehouhui.cn',
site: 'Honesty的主页'
},
dev: {
isLocal: (typeof location !== 'undefined') ? (location.hostname.indexOf('localhost') > -1 || location.hostname.indexOf('127.0.0.1') > -1) : false
},
defaults: {
user: { repos: 165, followers: 6, created: "2018-05-14" },
repos: [
{name: "yunxiao-LLM-reviewer", desc: "AI Code Reviewer based on LLM", stars: 9, url: "#"},
{name: "hexo-theme-stellar", desc: "Comprehensive Hexo theme", stars: 5, url: "#"},
{name: "Universal-IoT-Java", desc: "IoT Platform Demo", stars: 2, url: "#"}
],
posts: [
{title: "Vector Database Guide", date: "2025-01-02", cat: "Tech", url: "#"},
{title: "Spring Boot 3.0 Features", date: "2024-12-30", cat: "Java", url: "#"},
{title: "Microservices Patterns", date: "2024-12-28", cat: "Arch", url: "#"}
]
}
};
window.SiteConfig = SiteConfig;
</script>
</head> </head>
<body> <body>
<!-- 动态背景层 --> <!-- 动态背景层 -->
@@ -446,14 +401,14 @@
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// 动态加载不蒜子统计脚本 // 动态加载不蒜子统计脚本
const script = document.createElement('script'); const script = document.createElement('script');
script.src = SiteConfig.analytics.busuanzi.src; script.src = "//cdn.busuanzi.cc/busuanzi/3.6.9/busuanzi.abbr.min.js";
script.async = true; script.async = true;
document.head.appendChild(script); document.head.appendChild(script);
}); });
</script> </script>
<script> <script>
try { try {
!function(p){"use strict";!function(t){var s=window,e=document,i=p,c="".concat("https:"===e.location.protocol?"https://":"http://","sdk.51.la/js-sdk-pro.min.js"),n=e.createElement("script"),r=e.getElementsByTagName("script")[0];n.type="text/javascript",n.setAttribute("charset","UTF-8"),n.async=!0,n.src=c,n.id="LA_COLLECT",i.d=n;var o=function(){s.LA.ids.push(i)};s.LA?s.LA.ids&&o():(s.LA=p,s.LA.ids=[],o()),r.parentNode.insertBefore(n,r)}()}({id: SiteConfig.analytics.tencent.id, ck: SiteConfig.analytics.tencent.ck}); !function(p){"use strict";!function(t){var s=window,e=document,i=p,c="".concat("https:"===e.location.protocol?"https://":"http://","sdk.51.la/js-sdk-pro.min.js"),n=e.createElement("script"),r=e.getElementsByTagName("script")[0];n.type="text/javascript",n.setAttribute("charset","UTF-8"),n.async=!0,n.src=c,n.id="LA_COLLECT",i.d=n;var o=function(){s.LA.ids.push(i)};s.LA?s.LA.ids&&o():(s.LA=p,s.LA.ids=[],o()),r.parentNode.insertBefore(n,r)}()}({id:"3OBGjwDdEIRS7XZ1",ck:"3OBGjwDdEIRS7XZ1"});
} catch (e) { } catch (e) {
console.log("51.la统计错误", e); console.log("51.la统计错误", e);
} }
@@ -465,7 +420,7 @@
(function () { (function () {
try { try {
var hm = document.createElement("script"); var hm = document.createElement("script");
hm.src = SiteConfig.analytics.baidu.src; hm.src = "https://hm.baidu.com/hm.js?ae2a009a75b13c21d5121ee51375ea4e";
var s = document.getElementsByTagName("script")[0]; var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s); s.parentNode.insertBefore(hm, s);
} catch (e) { } catch (e) {
@@ -479,8 +434,8 @@
<script> <script>
// 监听不蒜子数据的错误兜底 // 监听不蒜子数据的错误兜底
function initFormatter() { function initFormatter() {
const pvEl = document.getElementById(SiteConfig.analytics.busuanzi.site_pv_id); const pvEl = document.getElementById("busuanzi_site_pv");
const uvEl = document.getElementById(SiteConfig.analytics.busuanzi.site_uv_id); const uvEl = document.getElementById("busuanzi_site_uv");
if (!pvEl && !uvEl) return; if (!pvEl && !uvEl) return;
console.log('[Busuanzi]', 'Formatting... Listener observer'); console.log('[Busuanzi]', 'Formatting... Listener observer');

View File

@@ -1,179 +1,181 @@
// 配置文件 - 提取自各个JavaScript文件的关键配置 // 配置文件 - 提取自各个JavaScript文件的关键配置
// 创建日期: 2025-11-20 // 创建日期: 2025-11-20
const SiteConfig = { (function() {
// bj.js 配置 const SiteConfig = {
stars: { // bj.js 配置
count: 300, stars: {
refreshInterval: 50 count: 300,
}, refreshInterval: 50
},
// main.js 配置 // main.js 配置
animation: { animation: {
elementUp: { elementUp: {
delay: 0, delay: 0,
increment: 150 increment: 150
} }
}, },
background: { background: {
imagePaths: [ imagePaths: [
"/images/bj/1.webp", "/images/bj/1.webp",
"/images/bj/2.webp", "/images/bj/2.webp",
"/images/bj/3.webp", "/images/bj/3.webp",
"/images/bj/4.webp", "/images/bj/4.webp",
"/images/bj/5.webp", "/images/bj/5.webp",
"/images/bj/6.webp", "/images/bj/6.webp",
"/images/bj/7.webp" "/images/bj/7.webp"
] ]
}, },
hitokoto: { hitokoto: {
apiUrl: 'https://v1.hitokoto.cn?c=c&c=d&c=i&c=k' apiUrl: 'https://v1.hitokoto.cn?c=c&c=d&c=i&c=k'
}, },
// about.js 配置 // about.js 配置
github: { github: {
username: 'listener-He' username: 'listener-He'
}, },
blog: { blog: {
rssUrl: 'https://blog.hehouhui.cn/api/rss' rssUrl: 'https://blog.hehouhui.cn/api/rss'
}, },
// 通用缓存键与TTL毫秒 // 通用缓存键与TTL毫秒
cacheKeys: { cacheKeys: {
github: { key: 'gh_data', ttlMs: 36000000 }, github: { key: 'gh_data', ttlMs: 36000000 },
blog: { key: 'blog_data', ttlMs: 3600000 }, blog: { key: 'blog_data', ttlMs: 3600000 },
theme: { key: 'theme', ttlMs: 3600000 } theme: { key: 'theme', ttlMs: 3600000 }
}, },
techStack: [ techStack: [
{ name: 'Java', category: 'core', weight: 5 }, { name: 'Java', category: 'core', weight: 5 },
{ name: 'Spring Boot', category: 'backend', weight: 5 }, { name: 'Spring Boot', category: 'backend', weight: 5 },
{ name: 'JavaScript', category: 'frontend', weight: 5 }, { name: 'JavaScript', category: 'frontend', weight: 5 },
{ name: 'Python', category: 'core', weight: 4 }, { name: 'Python', category: 'core', weight: 4 },
{ name: 'WebFlux', category: 'backend', weight: 5 }, { name: 'WebFlux', category: 'backend', weight: 5 },
{ name: 'Reactor', category: 'backend', weight: 5 }, { name: 'Reactor', category: 'backend', weight: 5 },
{ name: 'TypeScript', category: 'frontend', weight: 4 }, { name: 'TypeScript', category: 'frontend', weight: 4 },
{ name: 'Spring Cloud', category: 'backend', weight: 4 }, { name: 'Spring Cloud', category: 'backend', weight: 4 },
{ name: 'Go', category: 'core', weight: 3 }, { name: 'Go', category: 'core', weight: 3 },
{ name: 'MySQL', category: 'data', weight: 4 }, { name: 'MySQL', category: 'data', weight: 4 },
{ name: 'Redis', category: 'data', weight: 4 }, { name: 'Redis', category: 'data', weight: 4 },
{ name: 'MongoDB', category: 'data', weight: 3 }, { name: 'MongoDB', category: 'data', weight: 3 },
{ name: 'Docker', category: 'ops', weight: 4 }, { name: 'Docker', category: 'ops', weight: 4 },
{ name: 'Kubernetes', category: 'ops', weight: 3 }, { name: 'Kubernetes', category: 'ops', weight: 3 },
{ name: 'OpenAI API', category: 'ai', weight: 3 }, { name: 'OpenAI API', category: 'ai', weight: 3 },
{ name: 'LangChain', category: 'ai', weight: 3 }, { name: 'LangChain', category: 'ai', weight: 3 },
{ name: 'TensorFlow', category: 'ai', weight: 2 }, { name: 'TensorFlow', category: 'ai', weight: 2 },
{ name: 'PyTorch', category: 'ai', weight: 2 }, { name: 'PyTorch', category: 'ai', weight: 2 },
{ name: 'Elasticsearch', category: 'data', weight: 3 }, { name: 'Elasticsearch', category: 'data', weight: 3 },
{ name: 'RabbitMQ', category: 'data', weight: 2 }, { name: 'RabbitMQ', category: 'data', weight: 2 },
{ name: 'RocketMQ', category: 'data', weight: 2 }, { name: 'RocketMQ', category: 'data', weight: 2 },
{ name: 'Kafka', category: 'data', weight: 2 }, { name: 'Kafka', category: 'data', weight: 2 },
{ name: 'Jenkins', category: 'ops', weight: 3 }, { name: 'Jenkins', category: 'ops', weight: 3 },
{ name: 'Git', category: 'ops', weight: 4 }, { name: 'Git', category: 'ops', weight: 4 },
{ name: 'Linux', category: 'ops', weight: 3 }, { name: 'Linux', category: 'ops', weight: 3 },
{ name: 'AWS', category: 'ops', weight: 2 }, { name: 'AWS', category: 'ops', weight: 2 },
{ name: 'Nginx', category: 'ops', weight: 2 }, { name: 'Nginx', category: 'ops', weight: 2 },
{ name: 'Spring Security', category: 'backend', weight: 3 }, { name: 'Spring Security', category: 'backend', weight: 3 },
{ name: 'MyBatis', category: 'backend', weight: 3 }, { name: 'MyBatis', category: 'backend', weight: 3 },
{ name: 'JPA', category: 'backend', weight: 2 }, { name: 'JPA', category: 'backend', weight: 2 },
{ name: 'Dubbo', category: 'backend', weight: 2 }, { name: 'Dubbo', category: 'backend', weight: 2 },
{ name: 'Netty', category: 'backend', weight: 2 }, { name: 'Netty', category: 'backend', weight: 2 },
{ name: 'Transformers', category: 'ai', weight: 2 }, { name: 'Transformers', category: 'ai', weight: 2 },
{ name: 'Scikit-learn', category: 'ai', weight: 2 }, { name: 'Scikit-learn', category: 'ai', weight: 2 },
{ name: 'Ollama', category: 'ai', weight: 1 }, { name: 'Ollama', category: 'ai', weight: 1 },
{ name: 'Dify', category: 'ai', weight: 1 }, { name: 'Dify', category: 'ai', weight: 1 },
{ name: 'Spring AI', category: 'ai', weight: 1 }, { name: 'Spring AI', category: 'ai', weight: 1 },
{ name: 'ClickHouse', category: 'data', weight: 1 }, { name: 'ClickHouse', category: 'data', weight: 1 },
{ name: 'Postgresql', category: 'data', weight: 1 }, { name: 'Postgresql', category: 'data', weight: 1 },
{ name: "Hexo", category: "frontend", weight: 5}, { name: "Hexo", category: "frontend", weight: 5},
{ name: "NextJs", category: "frontend", weight: 1}, { name: "NextJs", category: "frontend", weight: 1},
{ name: "HuggingFace", category: "ai", weight: 1}, { name: "HuggingFace", category: "ai", weight: 1},
{ name: "Vue", category: "frontend", weight: 3}, { name: "Vue", category: "frontend", weight: 3},
{ name: "React", category: "frontend", weight: 1}, { name: "React", category: "frontend", weight: 1},
{ name: "R2dbc", category: "data", weight: 1}, { name: "R2dbc", category: "data", weight: 1},
{ name: "Proto", category: "core", weight: 1}, { name: "Proto", category: "core", weight: 1},
{ name: "Mqtt", category: "core", weight: 2}, { name: "Mqtt", category: "core", weight: 2},
{ name: "Grpc", category: "core", weight: 1}, { name: "Grpc", category: "core", weight: 1},
{ name: "Figma", category: "frontend", weight: 1} { name: "Figma", category: "frontend", weight: 1}
],
// 默认数据当API或RSS不可用时使用
defaults: {
repos: [
{name: "yunxiao-LLM-reviewer", desc: "AI Code Reviewer based on LLM", stars: 9, url: "#"},
{name: "hexo-theme-stellar", desc: "Comprehensive Hexo theme", stars: 5, url: "#"},
{name: "Universal-IoT-Java", desc: "IoT Platform Demo", stars: 2, url: "#"}
], ],
posts: [
{title: "Vector Database Guide", date: "2025-01-02", cat: "Tech", url: "#"},
{title: "Spring Boot 3.0 Features", date: "2024-12-30", cat: "Java", url: "#"},
{title: "Microservices Patterns", date: "2024-12-28", cat: "Arch", url: "#"}
],
user: { repos: 165, followers: 6, created: "2018-05-14" }
},
socialCards: {
rings: [130, 180, 230],
goldenAngle: 137.5,
baseSpeed: 16
},
artalk: { // 默认数据当API或RSS不可用时使用
server: 'https://artalk.hehouhui.cn', defaults: {
site: 'Honesty的主页', repos: [
placeholder: '来说点什么吧...', {name: "yunxiao-LLM-reviewer", desc: "AI Code Reviewer based on LLM", stars: 9, url: "#"},
noComment: '暂无评论', {name: "hexo-theme-stellar", desc: "Comprehensive Hexo theme", stars: 5, url: "#"},
sendBtn: '发送' {name: "Universal-IoT-Java", desc: "IoT Platform Demo", stars: 2, url: "#"}
}, ],
posts: [
{title: "Vector Database Guide", date: "2025-01-02", cat: "Tech", url: "#"},
{title: "Spring Boot 3.0 Features", date: "2024-12-30", cat: "Java", url: "#"},
{title: "Microservices Patterns", date: "2024-12-28", cat: "Arch", url: "#"}
],
user: { repos: 165, followers: 6, created: "2018-05-14" }
},
// 站点统计配置 socialCards: {
analytics: { rings: [130, 180, 230],
busuanzi: { goldenAngle: 137.5,
src: '//cdn.busuanzi.cc/busuanzi/3.6.9/busuanzi.abbr.min.js', baseSpeed: 16
site_pv_id: 'busuanzi_site_pv',
site_uv_id: 'busuanzi_site_uv',
formatter: true
}, },
baidu: {
src: 'https://hm.baidu.com/hm.js?ae2a009a75b13c21d5121ee51375ea4e', artalk: {
id: 'ae2a009a75b13c21d5121ee51375ea4e' server: 'https://artalk.hehouhui.cn',
site: 'Honesty的主页',
placeholder: '来说点什么吧...',
noComment: '暂无评论',
sendBtn: '发送'
}, },
google: {
src: 'https://www.googletagmanager.com/gtag/js', // 站点统计配置
id: 'G-DYWDEVKDP0' analytics: {
busuanzi: {
src: '//cdn.busuanzi.cc/busuanzi/3.6.9/busuanzi.abbr.min.js',
site_pv_id: 'busuanzi_site_pv',
site_uv_id: 'busuanzi_site_uv',
formatter: true
},
baidu: {
src: 'https://hm.baidu.com/hm.js?ae2a009a75b13c21d5121ee51375ea4e',
id: 'ae2a009a75b13c21d5121ee51375ea4e'
},
google: {
src: 'https://www.googletagmanager.com/gtag/js',
id: 'G-DYWDEVKDP0'
},
tencent: {
src: 'https://sdk.51.la/js-sdk-pro.min.js',
id: '3OBGjwDdEIRS7XZ1',
ck: '3OBGjwDdEIRS7XZ1'
}
}, },
tencent: {
src: 'https://sdk.51.la/js-sdk-pro.min.js', animationSettings: {
id: '3OBGjwDdEIRS7XZ1', observerOptions: {
ck: '3OBGjwDdEIRS7XZ1' threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
},
itemObserverOptions: {
threshold: 0.15,
rootMargin: '0px 0px -20px 0px'
}
},
// 开发环境配置
dev: {
isLocal: (typeof location !== 'undefined') ? (location.hostname.indexOf('localhost') > -1 || location.hostname.indexOf('127.0.0.1') > -1) : false
} }
}, };
animationSettings: {
observerOptions: {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
},
itemObserverOptions: {
threshold: 0.15,
rootMargin: '0px 0px -20px 0px'
}
},
// 开发环境配置 // 导出配置
dev: { if (typeof module !== 'undefined' && module.exports) {
isLocal: (typeof location !== 'undefined') ? (location.hostname.indexOf('localhost') > -1 || location.hostname.indexOf('127.0.0.1') > -1) : false module.exports = SiteConfig;
} else if (typeof window !== 'undefined') {
window.SiteConfig = SiteConfig;
} }
}; })();
// 导出配置
if (typeof module !== 'undefined' && module.exports) {
module.exports = SiteConfig;
} else if (typeof window !== 'undefined') {
window.SiteConfig = SiteConfig;
}