feat(config): 提取站点配置到独立的config.js文件
- 将分散在各JS文件中的配置项统一提取到SiteConfig对象中 - 包含stars、animation、background、hitokoto等配置模块 - GitHub相关配置包括用户名、缓存键值和过期时间 - 博客RSS地址及缓存配置迁移至config.js - 技术栈数据从硬编码移至配置文件管理 - 社交卡片动画参数统一配置化 - Artalk评论系统参数集中管理 - 添加开发环境检测逻辑 - 支持CommonJS和浏览器环境下的配置导出 - 在about.html和index.html中引入config.js脚本 - 更新about.js和main.js以使用SiteConfig配置 - 删除重复的GitHub用户名硬编码 - 调整图片路径读取方式为配置驱动 - 优化星空背景脚本的配置引用方式 - 修复本地开发环境下的一言默认文本显示问题
This commit is contained in:
20
js/main.js
20
js/main.js
@@ -30,12 +30,20 @@ var iUp = (function () {
|
||||
$(document).ready(function () {
|
||||
|
||||
// 获取一言数据
|
||||
fetch('https://v1.hitokoto.cn?c=c&c=d&c=i&c=k').then(function (res) {
|
||||
// 检查是否在本地开发环境
|
||||
var isLocal = location.hostname === 'localhost' || location.hostname === '127.0.0.1';
|
||||
var hitokotoUrl = isLocal ? 'https://v1.hitokoto.cn/' : SiteConfig.hitokoto.apiUrl;
|
||||
|
||||
fetch(hitokotoUrl).then(function (res) {
|
||||
return res.json();
|
||||
}).then(function (e) {
|
||||
$('#description').html(e.hitokoto + "<br/> -「<strong>" + e.from + "</strong>」")
|
||||
}).catch(function (err) {
|
||||
console.error("获取一言数据失败", err);
|
||||
// 本地开发环境使用默认文本
|
||||
if (isLocal) {
|
||||
$('#description').html('人生天地之间,若白驹之过隙,忽然而已。<br/> -「<strong>Honesty</strong>」');
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -49,9 +57,9 @@ $(document).ready(function () {
|
||||
if (imgUrls == null) {
|
||||
imgUrls = [];
|
||||
index = 0;
|
||||
for (let i = 1; i < 8; i++) {
|
||||
imgUrls.push("/images/bj/"+i+".jpg");
|
||||
}
|
||||
SiteConfig.background.imagePaths.forEach(path => {
|
||||
imgUrls.push(path);
|
||||
});
|
||||
sessionStorage.setItem("imgUrls", JSON.stringify(imgUrls));
|
||||
// sessionStorage.setItem("index", index);
|
||||
} else {
|
||||
@@ -87,6 +95,4 @@ $('.btn-mobile-menu__icon').click(function () {
|
||||
$('.navigation-wrapper').toggleClass('visible animated bounceInDown');
|
||||
}
|
||||
$('.btn-mobile-menu__icon').toggleClass('social iconfont icon-list social iconfont icon-ngleup animated fadeIn');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user