feat: 首页由 navigation 首项决定
- 移除 navigation.active 配置项,默认页以 navigation[0] 为准(生成端/前端一致) - 注入 homePageId;首页渲染用 profile.title/profile.subtitle 覆盖 title/subtitle - 模板按 homePageId 切换首页/非首页标题 DOM 与 data-editable,避免样式错位 - 更新默认配置与文档;书签导入不再写入 active 字段 - 新增/更新单测覆盖首页规则与 profile 覆盖 BREAKING CHANGE: 不再支持 navigation[].active;通过调整 navigation 顺序设置默认页/首页
This commit is contained in:
55
test/home-page-profile-override.node-test.js
Normal file
55
test/home-page-profile-override.node-test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
|
||||
const { loadHandlebarsTemplates, generateAllPagesHTML } = require('../src/generator.js');
|
||||
|
||||
test('首页(navigation 第一项)应使用 profile 覆盖 title/subtitle 显示', () => {
|
||||
const originalCwd = process.cwd();
|
||||
process.chdir(path.join(__dirname, '..'));
|
||||
|
||||
try {
|
||||
loadHandlebarsTemplates();
|
||||
|
||||
const config = {
|
||||
site: { title: 'Test Site', description: '', author: '', favicon: '', logo_text: 'Test' },
|
||||
profile: { title: 'PROFILE_TITLE', subtitle: 'PROFILE_SUBTITLE' },
|
||||
social: [],
|
||||
navigation: [
|
||||
{ id: 'bookmarks', name: '书签', icon: 'fas fa-bookmark' },
|
||||
{ id: 'home', name: '首页', icon: 'fas fa-home' },
|
||||
{ id: 'projects', name: '项目', icon: 'fas fa-project-diagram' },
|
||||
],
|
||||
bookmarks: { title: '书签页标题', subtitle: '书签页副标题', template: 'bookmarks', categories: [] },
|
||||
home: { title: 'HOME_PAGE_TITLE', subtitle: 'HOME_PAGE_SUBTITLE', template: 'home', categories: [] },
|
||||
projects: { title: '项目页标题', subtitle: '项目页副标题', template: 'projects', categories: [] },
|
||||
};
|
||||
|
||||
const pages = generateAllPagesHTML(config);
|
||||
|
||||
assert.ok(typeof pages.bookmarks === 'string' && pages.bookmarks.length > 0);
|
||||
assert.ok(pages.bookmarks.includes('PROFILE_TITLE'));
|
||||
assert.ok(pages.bookmarks.includes('PROFILE_SUBTITLE'));
|
||||
assert.ok(pages.bookmarks.includes('data-editable="profile-title"'));
|
||||
assert.ok(pages.bookmarks.includes('data-editable="profile-subtitle"'));
|
||||
assert.ok(pages.bookmarks.includes('<h3'));
|
||||
assert.ok(!pages.bookmarks.includes('书签页标题'));
|
||||
assert.ok(!pages.bookmarks.includes('书签页副标题'));
|
||||
assert.ok(!pages.bookmarks.includes('data-editable="page-title"'));
|
||||
|
||||
assert.ok(typeof pages.home === 'string' && pages.home.length > 0);
|
||||
assert.ok(pages.home.includes('HOME_PAGE_TITLE'));
|
||||
assert.ok(pages.home.includes('HOME_PAGE_SUBTITLE'));
|
||||
assert.ok(pages.home.includes('data-editable="page-title"'));
|
||||
assert.ok(pages.home.includes('data-editable="page-subtitle"'));
|
||||
assert.ok(pages.home.includes('<p class="subtitle"'));
|
||||
assert.ok(!pages.home.includes('PROFILE_TITLE'));
|
||||
|
||||
assert.ok(typeof pages.projects === 'string' && pages.projects.length > 0);
|
||||
assert.ok(pages.projects.includes('项目页标题'));
|
||||
assert.ok(pages.projects.includes('项目页副标题'));
|
||||
assert.ok(pages.projects.includes('<p class="subtitle"'));
|
||||
} finally {
|
||||
process.chdir(originalCwd);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user