Files
menav/test/home-page-profile-override.node-test.js
rbetree 387cd2492e feat: 页面模板差异化改进 + 配置优化 + 兼容清理 (#29)
- 首页判定: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
2025-12-28 00:22:54 +08:00

56 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
});