fix: 补齐书签 subgroups 渲染并对齐 README

- 修复 subgroups 生成但不展示的问题(模板渲染 + 前端结构导出)
- 更新 README:配置示例/完全替换策略/多层级说明与 helper 文档,减少重复说明
This commit is contained in:
rbetree
2025-12-22 02:08:05 +08:00
parent 2daba411ba
commit 670e73e93c
8 changed files with 222 additions and 88 deletions

View File

@@ -55,6 +55,62 @@ test('parseBookmarks解析书签栏、根目录书签与图标映射', () =>
assert.equal(tools.sites[0].name, 'Google');
});
test('templatessubgroups第4层应可渲染到页面', () => {
const Handlebars = require('handlebars');
const { registerAllHelpers } = require('../src/helpers');
const hbs = Handlebars.create();
registerAllHelpers(hbs);
const category = fs.readFileSync(path.join(__dirname, '..', 'templates', 'components', 'category.hbs'), 'utf8');
const group = fs.readFileSync(path.join(__dirname, '..', 'templates', 'components', 'group.hbs'), 'utf8');
const siteCard = fs.readFileSync(path.join(__dirname, '..', 'templates', 'components', 'site-card.hbs'), 'utf8');
const page = fs.readFileSync(path.join(__dirname, '..', 'templates', 'pages', 'bookmarks.hbs'), 'utf8');
hbs.registerPartial('category', category);
hbs.registerPartial('group', group);
hbs.registerPartial('site-card', siteCard);
const tpl = hbs.compile(page);
const html = tpl({
title: '我的书签',
subtitle: '测试 subgroups 渲染',
icons: { mode: 'manual' },
categories: [
{
name: '技术',
icon: 'fas fa-code',
subcategories: [
{
name: '前端',
icon: 'fas fa-laptop-code',
groups: [
{
name: '框架',
icon: 'fas fa-cubes',
subgroups: [
{
name: 'React生态',
icon: 'fab fa-react',
sites: [
{ name: 'React', url: 'https://reactjs.org/', icon: 'fab fa-react', description: 'React官方' },
],
},
],
},
],
},
],
},
],
});
assert.ok(html.includes('subgroups-container'), '应输出 subgroups-container 容器');
assert.ok(html.includes('group-level-4'), '应输出 level=4 的 group 样式类');
assert.ok(html.includes('React生态'), '应渲染子分组标题文本');
});
test('generateBookmarksYaml生成 YAML 且可被解析', () => {
const bookmarks = {
categories: [
@@ -122,4 +178,3 @@ test('ensureUserConfigInitialized/ensureUserSiteYmlExists可在空目录初
process.chdir(originalCwd);
}
});