feat(icons): 添加favicon模式,自动匹配图标

- 新增配置 icons.mode(manual | favicon),默认 favicon,未配置场景下自动生效
- 模板调用 t3.gstatic.com/faviconV2 获取站点图标;加载中显示旋转占位,失败回退至 Font Awesome 图标
- 新增 ifHttpUrl 与 encodeURIComponent,提升模板安全性与可读性
- 搜索索引优先读取 .icon-fallback,保证 favicon 模式下图标类名一致
- 样式新增 .favicon-icon 与 hover 效果,维持卡片观感一致性
This commit is contained in:
coolzr
2025-10-18 22:32:05 +08:00
parent 95398e074a
commit aa264cc727
6 changed files with 109 additions and 14 deletions

View File

@@ -159,6 +159,20 @@ function not(value, options) {
return !value ? options.fn(this) : options.inverse(this);
}
/**
* 判断URL是否为http/https
* @param {string} url 输入URL
* @param {object} options Handlebars选项
* @returns {string} 渲染结果
* @example {{#ifHttpUrl url}}...{{else}}...{{/ifHttpUrl}}
*/
function ifHttpUrl(url, options) {
if (typeof url === 'string' && /^https?:\/\//i.test(url)) {
return options.fn(this);
}
return options.inverse(this);
}
// 导出所有条件判断助手函数
module.exports = {
ifEquals,
@@ -169,5 +183,6 @@ module.exports = {
and,
or,
orHelper,
not
};
not,
ifHttpUrl
};

View File

@@ -166,6 +166,21 @@ function keys(object) {
return Object.keys(object);
}
/**
* 对字符串进行URL组件编码encodeURIComponent
* @param {string} text 输入文本
* @returns {string} 编码后的字符串
* @example {{encodeURIComponent url}}
*/
function encodeURIComponentHelper(text) {
if (text === undefined || text === null) return '';
try {
return encodeURIComponent(String(text));
} catch (e) {
return '';
}
}
// 导出所有工具类助手函数
module.exports = {
slice,
@@ -175,5 +190,6 @@ module.exports = {
last,
range,
pick,
keys
};
keys,
encodeURIComponent: encodeURIComponentHelper
};