- 首页判定:navigation 第一项 - 模板:page/projects/articles/bookmarks/search-results - bookmarks:update: YYYY-MM-DD | from: git|mtime - articles:RSS 聚合只读条目 + 分类聚合 + 影子写回结构 - projects:repo 卡片 + 可选热力图 + 自动抓取元信息 - 工作流:构建前 sync + schedule 定时刷新 - 移除兼容:config.yml/config.yaml、navigation.yml、home 特例 - 迁移说明:config/update-instructions.md
56 lines
2.6 KiB
JavaScript
56 lines
2.6 KiB
JavaScript
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: 'page', 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);
|
||
}
|
||
});
|