fix: 重命名 favicon helper 避免与 sites.faviconUrl 同名冲突

将 Handlebars helper `faviconUrl(url)` 更名为 `faviconV2Url(url)`,解决自定义字段 `sites[].faviconUrl`
在模板中被误解析为 helper(无参调用)导致的渲染崩溃。

- helper:faviconUrl -> faviconV2Url
- 模板:site-card 中调用同步更新

BREAKING CHANGE:
自定义模板如使用 `{{faviconUrl url}}` 生成 faviconV2 地址,需要改为 `{{faviconV2Url url}}`。

Fixes: #32
This commit is contained in:
rbetree
2026-01-04 19:15:39 +08:00
parent 9929f60170
commit 3d9363a550
6 changed files with 99 additions and 12 deletions

View File

@@ -0,0 +1,76 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const { loadHandlebarsTemplates, renderTemplate } = require('../src/generator.js');
function withRepoCwd(callback) {
const originalCwd = process.cwd();
const repoRoot = path.join(__dirname, '..');
try {
process.chdir(repoRoot);
callback();
} finally {
process.chdir(originalCwd);
}
}
function renderBookmarksWithSite(site) {
loadHandlebarsTemplates();
return renderTemplate(
'bookmarks',
{
pageId: 'bookmarks',
homePageId: 'bookmarks',
title: '书签',
subtitle: '测试',
siteCardStyle: '',
icons: { mode: 'favicon', region: 'com' },
categories: [
{
name: '分类',
icon: 'fas fa-folder',
sites: [site]
}
]
},
false
);
}
test('站点配置包含 faviconUrl本地 assets 路径)时,渲染 bookmarks 不应崩溃', () => {
withRepoCwd(() => {
const html = renderBookmarksWithSite({
name: '内部系统',
url: 'https://intranet.example/',
faviconUrl: 'assets/menav.svg',
icon: 'fas fa-link',
external: true
});
assert.match(html, /data-favicon-url="assets\/menav\.svg"/);
assert.match(html, /src="assets\/menav\.svg"/);
});
});
test('站点配置包含 faviconUrl在线 ico渲染 bookmarks 不应崩溃', () => {
withRepoCwd(() => {
const html = renderBookmarksWithSite({
name: 'WebCull',
url: 'https://example.com/',
faviconUrl: 'https://content.webcull.com/images/websites/icons/470/695/b788b0.ico',
icon: 'fas fa-link',
external: true
});
assert.match(
html,
/data-favicon-url="https:\/\/content\.webcull\.com\/images\/websites\/icons\/470\/695\/b788b0\.ico"/
);
assert.match(
html,
/src="https:\/\/content\.webcull\.com\/images\/websites\/icons\/470\/695\/b788b0\.ico"/
);
});
});