feat: 分类锚点&质量检查&依赖治理

- 分类生成唯一 slug,模板/子菜单/滚动/扩展定位统一使用 data-id
- lint 覆盖 src/scripts/test,CI 增量格式检查
- 清理冗余依赖,升级 esbuild,overrides 修复审计项
- 补充单测并更新修复清单
This commit is contained in:
rbetree
2026-01-04 20:39:42 +08:00
parent 3d9363a550
commit 48609b86de
11 changed files with 641 additions and 224 deletions

View File

@@ -0,0 +1,43 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const { loadHandlebarsTemplates, generateHTML } = require('../src/generator.js');
function withRepoRoot(fn) {
const originalCwd = process.cwd();
process.chdir(path.join(__dirname, '..'));
try {
return fn();
} finally {
process.chdir(originalCwd);
}
}
test('P1-2子菜单锚点应使用分类 slughref + data-category-id', () => {
withRepoRoot(() => {
loadHandlebarsTemplates();
const config = {
site: { title: 'Test Site', description: '', author: '', favicon: '', logo_text: 'Test' },
profile: { title: 'PROFILE_TITLE', subtitle: 'PROFILE_SUBTITLE' },
social: [],
navigation: [{ id: 'home', name: '首页', icon: 'fas fa-home' }],
home: {
title: 'HOME',
subtitle: 'HOME_SUB',
template: 'page',
categories: [
{ name: '重复 分类', icon: 'fas fa-tag', sites: [] },
{ name: '重复 分类', icon: 'fas fa-tag', sites: [] },
],
},
};
const html = generateHTML(config);
assert.ok(html.includes('class="submenu-item"'), '应输出子菜单项');
assert.ok(html.includes('href="#重复-分类"'), '子菜单 href 应指向 slug');
assert.ok(html.includes('data-category-id="重复-分类"'), '子菜单应携带 data-category-id');
});
});