修复模块化配置的不完整加载问题
完成了模块化配置文件中的home.yml和site.yml的完整加载
This commit is contained in:
@@ -53,6 +53,10 @@
|
||||
- ✅ 修复搜索按钮和侧边栏按钮遮挡问题
|
||||
- ✅ 点击侧边栏导航项后自动收起侧边栏
|
||||
|
||||
**3. 配置加载优先级修复**
|
||||
- ✅ 修复了模块化配置目录加载时的关键问题,确保site.yml中的fonts、profile和social配置正确应用
|
||||
- ✅ 修复了home.yml中的categories配置未正确加载到导航首页的问题
|
||||
- ✅ 增强了配置加载逻辑,确保按照优先级规则完整应用配置
|
||||
|
||||
### 2025/05/02
|
||||
|
||||
|
||||
@@ -40,4 +40,61 @@ categories:
|
||||
- name: LeetCode
|
||||
url: https://leetcode.cn
|
||||
icon: fas fa-code
|
||||
description: 算法刷题平台
|
||||
description: 算法刷题平台
|
||||
- name: 开发工具
|
||||
icon: fas fa-tools
|
||||
sites:
|
||||
- name: VS Code
|
||||
url: https://code.visualstudio.com
|
||||
icon: fas fa-code
|
||||
description: 强大的代码编辑器
|
||||
- name: Postman
|
||||
url: https://www.postman.com
|
||||
icon: fas fa-paper-plane
|
||||
description: API调试工具
|
||||
- name: Git
|
||||
url: https://git-scm.com
|
||||
icon: fab fa-git-alt
|
||||
description: 版本控制工具
|
||||
- name: Docker
|
||||
url: https://www.docker.com
|
||||
icon: fab fa-docker
|
||||
description: 容器化平台
|
||||
- name: 设计资源
|
||||
icon: fas fa-palette
|
||||
sites:
|
||||
- name: Figma
|
||||
url: https://www.figma.com
|
||||
icon: fab fa-figma
|
||||
description: 在线设计工具
|
||||
- name: Dribbble
|
||||
url: https://dribbble.com
|
||||
icon: fab fa-dribbble
|
||||
description: 设计师社区
|
||||
- name: Behance
|
||||
url: https://www.behance.net
|
||||
icon: fab fa-behance
|
||||
description: 创意设计平台
|
||||
- name: IconFont
|
||||
url: https://www.iconfont.cn
|
||||
icon: fas fa-icons
|
||||
description: 图标资源库
|
||||
- name: 在线工具
|
||||
icon: fas fa-wrench
|
||||
sites:
|
||||
- name: JSON Editor
|
||||
url: https://jsoneditoronline.org
|
||||
icon: fas fa-code-branch
|
||||
description: JSON在线编辑器
|
||||
- name: Can I Use
|
||||
url: https://caniuse.com
|
||||
icon: fas fa-browser
|
||||
description: 浏览器兼容性查询
|
||||
- name: TinyPNG
|
||||
url: https://tinypng.com
|
||||
icon: fas fa-compress
|
||||
description: 图片压缩工具
|
||||
- name: Carbon
|
||||
url: https://carbon.now.sh
|
||||
icon: fas fa-code
|
||||
description: 代码图片生成器
|
||||
@@ -59,7 +59,16 @@ function loadModularConfig(dirPath) {
|
||||
if (fs.existsSync(siteConfigPath)) {
|
||||
try {
|
||||
const fileContent = fs.readFileSync(siteConfigPath, 'utf8');
|
||||
config.site = yaml.load(fileContent);
|
||||
const siteConfig = yaml.load(fileContent);
|
||||
|
||||
// 将site.yml中的内容分配到正确的配置字段
|
||||
config.site = siteConfig;
|
||||
|
||||
// 提取特殊字段到顶层配置
|
||||
if (siteConfig.fonts) config.fonts = siteConfig.fonts;
|
||||
if (siteConfig.profile) config.profile = siteConfig.profile;
|
||||
if (siteConfig.social) config.social = siteConfig.social;
|
||||
|
||||
console.log(`Loaded site configuration from ${siteConfigPath}`);
|
||||
} catch (e) {
|
||||
console.error(`Error loading site configuration from ${siteConfigPath}:`, e);
|
||||
@@ -92,6 +101,11 @@ function loadModularConfig(dirPath) {
|
||||
// 提取文件名(不含扩展名)作为配置键
|
||||
const configKey = path.basename(file, path.extname(file));
|
||||
|
||||
// 特殊处理home.yml中的categories字段
|
||||
if (configKey === 'home' && fileConfig.categories) {
|
||||
config.categories = fileConfig.categories;
|
||||
}
|
||||
|
||||
// 将页面配置添加到主配置对象
|
||||
config[configKey] = fileConfig;
|
||||
|
||||
@@ -136,7 +150,30 @@ function loadConfig() {
|
||||
} else if (hasDefaultModularConfig) {
|
||||
// 3. 其次优先级: config/_default/ 目录
|
||||
console.log('Using modular default configuration from config/_default/');
|
||||
|
||||
// 从模块化默认配置加载
|
||||
config = loadModularConfig('config/_default');
|
||||
|
||||
// 检查并加载home.yml中的categories(如果loadModularConfig未正确处理)
|
||||
const homePath = path.join('config', '_default', 'pages', 'home.yml');
|
||||
if (fs.existsSync(homePath) && (!config.categories || config.categories.length === 0)) {
|
||||
try {
|
||||
const homeContent = fs.readFileSync(homePath, 'utf8');
|
||||
const homeConfig = yaml.load(homeContent);
|
||||
|
||||
if (homeConfig && homeConfig.categories) {
|
||||
// 直接设置categories
|
||||
config.categories = homeConfig.categories;
|
||||
|
||||
// 确保home配置也正确设置
|
||||
if (!config.home) {
|
||||
config.home = homeConfig;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error loading home.yml: ${e.message}`);
|
||||
}
|
||||
}
|
||||
} else if (hasDefaultLegacyConfig) {
|
||||
// 4. 最低优先级: config.yml (传统默认配置)
|
||||
console.log('Using legacy default config.yml');
|
||||
|
||||
Reference in New Issue
Block a user