chore: 使用 Prettier 统一代码风格
This commit is contained in:
@@ -15,7 +15,7 @@ const {
|
||||
function stripYamlComments(yamlText) {
|
||||
return yamlText
|
||||
.split(/\r?\n/)
|
||||
.filter(line => !/^\s*#/.test(line))
|
||||
.filter((line) => !/^\s*#/.test(line))
|
||||
.join('\n')
|
||||
.trim();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ test('parseBookmarks:解析书签栏、根目录书签与图标映射', () =>
|
||||
assert.equal(bookmarks.categories[0].sites[0].name, 'GitHub');
|
||||
assert.equal(bookmarks.categories[0].sites[0].icon, 'fab fa-github');
|
||||
|
||||
const tools = bookmarks.categories.find(c => c.name === '工具');
|
||||
const tools = bookmarks.categories.find((c) => c.name === '工具');
|
||||
assert.ok(tools, '应解析出“工具”分类');
|
||||
assert.ok(Array.isArray(tools.sites));
|
||||
assert.equal(tools.sites[0].name, 'Google');
|
||||
@@ -62,11 +62,26 @@ test('templates:subgroups(第4层)应可渲染到页面', () => {
|
||||
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 pageHeader = fs.readFileSync(path.join(__dirname, '..', 'templates', 'components', 'page-header.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');
|
||||
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 pageHeader = fs.readFileSync(
|
||||
path.join(__dirname, '..', 'templates', 'components', 'page-header.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);
|
||||
@@ -96,7 +111,12 @@ test('templates:subgroups(第4层)应可渲染到页面', () => {
|
||||
name: 'React生态',
|
||||
icon: 'fab fa-react',
|
||||
sites: [
|
||||
{ name: 'React', url: 'https://reactjs.org/', icon: 'fab fa-react', description: 'React官方' },
|
||||
{
|
||||
name: 'React',
|
||||
url: 'https://reactjs.org/',
|
||||
icon: 'fab fa-react',
|
||||
description: 'React官方',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -119,7 +139,9 @@ test('generateBookmarksYaml:生成 YAML 且可被解析', () => {
|
||||
{
|
||||
name: '示例分类',
|
||||
icon: 'fas fa-folder',
|
||||
sites: [{ name: 'Example', url: 'https://example.com', icon: 'fas fa-link', description: '' }],
|
||||
sites: [
|
||||
{ name: 'Example', url: 'https://example.com', icon: 'fas fa-link', description: '' },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -140,11 +162,7 @@ test('upsertBookmarksNavInSiteYml:无 navigation 时追加并幂等', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'menav-test-'));
|
||||
const filePath = path.join(tmp, 'site.yml');
|
||||
|
||||
fs.writeFileSync(
|
||||
filePath,
|
||||
`title: Test Site\n`,
|
||||
'utf8',
|
||||
);
|
||||
fs.writeFileSync(filePath, `title: Test Site\n`, 'utf8');
|
||||
|
||||
const r1 = upsertBookmarksNavInSiteYml(filePath);
|
||||
assert.equal(r1.updated, true);
|
||||
|
||||
@@ -30,9 +30,9 @@ function renderBookmarksWithSite(site) {
|
||||
{
|
||||
name: '分类',
|
||||
icon: 'fas fa-folder',
|
||||
sites: [site]
|
||||
}
|
||||
]
|
||||
sites: [site],
|
||||
},
|
||||
],
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -45,7 +45,7 @@ test('站点配置包含 faviconUrl(本地 assets 路径)时,渲染 bookma
|
||||
url: 'https://intranet.example/',
|
||||
faviconUrl: 'assets/menav.svg',
|
||||
icon: 'fas fa-link',
|
||||
external: true
|
||||
external: true,
|
||||
});
|
||||
|
||||
assert.match(html, /data-favicon-url="assets\/menav\.svg"/);
|
||||
@@ -60,7 +60,7 @@ test('站点配置包含 faviconUrl(在线 ico)时,渲染 bookmarks 不应
|
||||
url: 'https://example.com/',
|
||||
faviconUrl: 'https://content.webcull.com/images/websites/icons/470/695/b788b0.ico',
|
||||
icon: 'fas fa-link',
|
||||
external: true
|
||||
external: true,
|
||||
});
|
||||
|
||||
assert.match(
|
||||
@@ -73,4 +73,3 @@ test('站点配置包含 faviconUrl(在线 ico)时,渲染 bookmarks 不应
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -20,9 +20,24 @@ test('首页(navigation 第一项)应使用 profile 覆盖 title/subtitle
|
||||
{ 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: [] },
|
||||
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);
|
||||
|
||||
@@ -46,4 +46,3 @@ test('未配置 icons.mode 时应回退为默认 favicon', () => {
|
||||
assert.equal(config.icons.mode, 'favicon');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ test('多级结构下 sites.external 未配置时应默认 true,且 external:f
|
||||
' - name: DeepExternalFalse',
|
||||
' url: https://example.com/deep-false',
|
||||
' external: false',
|
||||
''
|
||||
'',
|
||||
].join('\n'),
|
||||
'utf8'
|
||||
);
|
||||
@@ -67,4 +67,3 @@ test('多级结构下 sites.external 未配置时应默认 true,且 external:f
|
||||
assert.equal(deepSites[1].external, false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,14 @@ test('friends/articles:应恢复分类展示(扩展仍以 data-* 结构为
|
||||
{
|
||||
name: '技术博主',
|
||||
icon: 'fas fa-user-friends',
|
||||
sites: [{ name: 'Example', url: 'https://example.com', icon: 'fas fa-link', description: 'desc' }],
|
||||
sites: [
|
||||
{
|
||||
name: 'Example',
|
||||
url: 'https://example.com',
|
||||
icon: 'fas fa-link',
|
||||
description: 'desc',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -50,7 +57,14 @@ test('friends/articles:应恢复分类展示(扩展仍以 data-* 结构为
|
||||
{
|
||||
name: '最新文章',
|
||||
icon: 'fas fa-pen',
|
||||
sites: [{ name: 'Article A', url: 'https://example.com/a', icon: 'fas fa-link', description: 'summary' }],
|
||||
sites: [
|
||||
{
|
||||
name: 'Article A',
|
||||
url: 'https://example.com/a',
|
||||
icon: 'fas fa-link',
|
||||
description: 'summary',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -61,15 +75,27 @@ test('friends/articles:应恢复分类展示(扩展仍以 data-* 结构为
|
||||
assert.ok(typeof pages.friends === 'string' && pages.friends.length > 0);
|
||||
assert.ok(pages.friends.includes('page-template-friends'));
|
||||
assert.ok(pages.friends.includes('sites-grid'));
|
||||
assert.ok(pages.friends.includes('class="site-card'), 'friends 应使用普通 site-card 样式(图标在左,标题在右)');
|
||||
assert.ok(!pages.friends.includes('site-card-friend'), 'friends 不应使用 site-card-friend 变体样式');
|
||||
assert.ok(
|
||||
pages.friends.includes('class="site-card'),
|
||||
'friends 应使用普通 site-card 样式(图标在左,标题在右)'
|
||||
);
|
||||
assert.ok(
|
||||
!pages.friends.includes('site-card-friend'),
|
||||
'friends 不应使用 site-card-friend 变体样式'
|
||||
);
|
||||
assert.ok(pages.friends.includes('category-header'), 'friends 应输出分类标题结构');
|
||||
|
||||
assert.ok(typeof pages.articles === 'string' && pages.articles.length > 0);
|
||||
assert.ok(pages.articles.includes('page-template-articles'));
|
||||
assert.ok(pages.articles.includes('sites-grid'));
|
||||
assert.ok(pages.articles.includes('class="site-card'), 'articles 应使用普通 site-card 样式(图标在左,标题在右)');
|
||||
assert.ok(!pages.articles.includes('site-card-article'), 'articles 不应使用 site-card-article 变体样式');
|
||||
assert.ok(
|
||||
pages.articles.includes('class="site-card'),
|
||||
'articles 应使用普通 site-card 样式(图标在左,标题在右)'
|
||||
);
|
||||
assert.ok(
|
||||
!pages.articles.includes('site-card-article'),
|
||||
'articles 不应使用 site-card-article 变体样式'
|
||||
);
|
||||
assert.ok(pages.articles.includes('category-header'), 'articles 应输出分类标题结构');
|
||||
});
|
||||
});
|
||||
@@ -92,13 +118,22 @@ test('friends/articles:页面配置使用顶层 sites 时应自动映射为分
|
||||
title: '友情链接',
|
||||
subtitle: '朋友们',
|
||||
template: 'page',
|
||||
sites: [{ name: 'Example', url: 'https://example.com', icon: 'fas fa-link', description: 'desc' }],
|
||||
sites: [
|
||||
{ name: 'Example', url: 'https://example.com', icon: 'fas fa-link', description: 'desc' },
|
||||
],
|
||||
},
|
||||
articles: {
|
||||
title: '文章',
|
||||
subtitle: '文章入口',
|
||||
template: 'articles',
|
||||
sites: [{ name: 'Article A', url: 'https://example.com/a', icon: 'fas fa-link', description: 'summary' }],
|
||||
sites: [
|
||||
{
|
||||
name: 'Article A',
|
||||
url: 'https://example.com/a',
|
||||
icon: 'fas fa-link',
|
||||
description: 'summary',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -107,15 +142,27 @@ test('friends/articles:页面配置使用顶层 sites 时应自动映射为分
|
||||
assert.ok(typeof pages.friends === 'string' && pages.friends.length > 0);
|
||||
assert.ok(pages.friends.includes('page-template-friends'));
|
||||
assert.ok(pages.friends.includes('sites-grid'));
|
||||
assert.ok(pages.friends.includes('class="site-card'), 'friends 应使用普通 site-card 样式(图标在左,标题在右)');
|
||||
assert.ok(!pages.friends.includes('site-card-friend'), 'friends 不应使用 site-card-friend 变体样式');
|
||||
assert.ok(
|
||||
pages.friends.includes('class="site-card'),
|
||||
'friends 应使用普通 site-card 样式(图标在左,标题在右)'
|
||||
);
|
||||
assert.ok(
|
||||
!pages.friends.includes('site-card-friend'),
|
||||
'friends 不应使用 site-card-friend 变体样式'
|
||||
);
|
||||
assert.ok(pages.friends.includes('category-header'), 'friends 应输出分类标题结构');
|
||||
|
||||
assert.ok(typeof pages.articles === 'string' && pages.articles.length > 0);
|
||||
assert.ok(pages.articles.includes('page-template-articles'));
|
||||
assert.ok(pages.articles.includes('sites-grid'));
|
||||
assert.ok(pages.articles.includes('class="site-card'), 'articles 应使用普通 site-card 样式(图标在左,标题在右)');
|
||||
assert.ok(!pages.articles.includes('site-card-article'), 'articles 不应使用 site-card-article 变体样式');
|
||||
assert.ok(
|
||||
pages.articles.includes('class="site-card'),
|
||||
'articles 应使用普通 site-card 样式(图标在左,标题在右)'
|
||||
);
|
||||
assert.ok(
|
||||
!pages.articles.includes('site-card-article'),
|
||||
'articles 不应使用 site-card-article 变体样式'
|
||||
);
|
||||
assert.ok(pages.articles.includes('category-header'), 'articles 应输出分类标题结构');
|
||||
});
|
||||
});
|
||||
@@ -191,7 +238,14 @@ test('projects:应输出代码仓库风格卡片(site-card-repo)', () => {
|
||||
{
|
||||
name: '项目',
|
||||
icon: 'fas fa-code',
|
||||
sites: [{ name: 'Proj', url: 'https://example.com', icon: 'fas fa-link', description: 'desc' }],
|
||||
sites: [
|
||||
{
|
||||
name: 'Proj',
|
||||
url: 'https://example.com',
|
||||
icon: 'fas fa-link',
|
||||
description: 'desc',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -231,10 +285,10 @@ test('articles Phase 2:存在 RSS 缓存时渲染文章条目,并隐藏扩
|
||||
publishedAt: '2025-12-25T12:00:00.000Z',
|
||||
source: 'Example Blog',
|
||||
sourceUrl: 'https://example.com',
|
||||
icon: 'fas fa-pen'
|
||||
}
|
||||
icon: 'fas fa-pen',
|
||||
},
|
||||
],
|
||||
stats: { totalArticles: 1 }
|
||||
stats: { totalArticles: 1 },
|
||||
},
|
||||
null,
|
||||
2
|
||||
@@ -259,7 +313,14 @@ test('articles Phase 2:存在 RSS 缓存时渲染文章条目,并隐藏扩
|
||||
{
|
||||
name: '来源',
|
||||
icon: 'fas fa-pen',
|
||||
sites: [{ name: 'Source A', url: 'https://example.com', icon: 'fas fa-link', description: 'desc' }],
|
||||
sites: [
|
||||
{
|
||||
name: 'Source A',
|
||||
url: 'https://example.com',
|
||||
icon: 'fas fa-link',
|
||||
description: 'desc',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -269,7 +330,10 @@ test('articles Phase 2:存在 RSS 缓存时渲染文章条目,并隐藏扩
|
||||
const html = pages.articles;
|
||||
|
||||
assert.ok(typeof html === 'string' && html.length > 0);
|
||||
assert.ok(html.includes('data-type="article"'), '文章条目卡片应为 data-type="article"(只读)');
|
||||
assert.ok(
|
||||
html.includes('data-type="article"'),
|
||||
'文章条目卡片应为 data-type="article"(只读)'
|
||||
);
|
||||
assert.ok(html.includes('site-card-meta'), '文章条目应展示日期/来源元信息');
|
||||
assert.ok(html.includes('Example Blog'));
|
||||
assert.ok(html.includes('2025-12-25'));
|
||||
|
||||
Reference in New Issue
Block a user