目录
用腻了之前的主题,况且之前使用的主题由日本人开发,显示的字体非简体中文字形,看起来别扭。
更换为 Farallon主题 ,借助 ChatGPT 5.4、5.3-codex 与 GLM 5.2,修改了主题的样式和功能,使其更适合笔者的需求。
改动如下:
🚀 新特性
1. 站点图标与 SEO 元信息增强
- 文件:
themes/farallon/layouts/partials/head.html、partials/favicon.html(新增)、partials/cover.html(新增) - 说明:
- 新增
params.favicon配置项,支持本地资源路径、远程 URL 与assets资源 - favicon 解析逻辑提取为
partials/favicon.html,仅输出单一<link rel="icon">,默认回退到主题内置favicon.png - 移除
vnd.microsoft.iconMIME 强制绑定与冗余的shortcut icon head.html重写完善 SEO:新增<link rel="canonical">、og:image/twitter:image(复用封面提取逻辑)、og:site_name、article:published_time- og 标签覆盖所有页面类型(原来仅文章页有),首页输出
og:type=website、文章页输出article - 移除过时的
X-UA-Compatible与重复 RSSfeed链接
- 新增
2. 配置项与显示控制重构
- 文件:
config.toml、themes/farallon/layouts/partials/profile.html、layouts/_default/baseof.html - 说明:
- 新增
showSiteDescription、showAuthorDescription开关,分别控制站点描述与作者描述显示,默认关闭 DEFAULT_THEME增加auto兜底,未配置时不再写入空值- 移除已失效的
showAuthor配置项(文章作者卡片已整体移除,详见第 4 条)
- 新增
🎨 样式与界面优化
3. 分类模块视觉优化
- 文件:
themes/farallon/layouts/partials/category.html、assets/scss/modules/_categoryCard.scss - 说明:
- 增加“分类”标签标题,提升语义清晰度
- 描述文本改为有值才渲染,避免空行占位
- 分类项样式从分割线列表改为轻量卡片:缩小内边距与封面尺寸、降低标题字号字重、
hover用浅背景细边框、描述限两行截断
4. 界面元素精简
- 文件:
themes/farallon/layouts/partials/profile.html、layouts/_default/single.html、config.toml - 说明:
- 移除首页
fWidgetAuthor--name作者名元素 - 移除文章末尾整个作者卡片(
fAuthor、fAuthor--name、fAuthor--description、fAuthor--icons及头像),避免authorAvatar未配置时src=""的显示问题 - 清理
config.toml中已失效的showAuthor配置项
- 移除首页
5. 代码块行号排版修复
- 文件:
themes/farallon/assets/scss/modules/_graph.scss - 说明:
- 修复因缺少 Hugo Chroma 专用样式导致的代码块行号错位
- 为
.highlight pre恢复white-space: pre和overflow-x: auto - 为
.highlight code移除内联代码背景与padding,防止双重样式叠加 - 为
.line设置display: block;为.ln设置固定宽度、右对齐与灰色字体,稳定行号列对齐
🐛 问题修复
6. 模板 Bug 修复
- 文件:
themes/farallon/layouts/_default/baseof.html、layouts/page/search.html、layouts/partials/category.html - 说明:
- 修复
<html lang>属性在未配置languageCode时输出前导空格(lang=" en") - 移除空的
<body class=""> - 删除搜索页重复渲染的
#searchbox容器 - 修复
category.html在with块内访问.Params.description的字段错误(分类配置description时必崩的隐藏 bug)
- 修复
7. JS 运行时错误修复
- 文件:
themes/farallon/assets/ts/app.ts、assets/ts/action.ts - 说明:
app.ts的initSearch加空值守卫:search=false时不渲染搜索图标,避免null.addEventListener报错action.ts在actionDomain未配置时跳过所有后端请求(点赞、阅读量等),避免向站点自身发起/post/views404 请求
⚡ 性能与代码质量
8. 性能优化
- 文件:
themes/farallon/layouts/_default/_markup/render-image.html、layouts/page/search.html、layouts/partials/footer.html、assets/ts/search.ts(新增) - 说明:
- 正文与列表封面图统一加
loading="lazy" decoding="async";本地资源图片自动输出width/height,减少布局偏移(CLS) - 搜索页约 110 行内联 JS 提取为
assets/ts/search.ts,与 Algolia 两个 vendor 库合并为单个 bundle,加defer与 fingerprint - 主 JS bundle 加 fingerprint,利于长缓存
- 搜索页文案接入 i18n(新增
search.emptyResult)
- 正文与列表封面图统一加
9. 消除代码重复(DRY)
- 文件:
themes/farallon/layouts/partials/(新增多个)、layouts/partials/menu.html(删除)、layouts/partials/navigation.html、layouts/partials/footer.html - 说明:
- 新增
cover.html:统一 4 处重复的封面提取正则 - 新增
favicon.html:统一 2 处重复的 favicon 解析逻辑 - 新增
icons/(date / category / views / readtime):替换 3 个文件中重复的长 SVG - 新增
like-button.html、toc.html、translated-card.html:替换两个 single 模板的重复块 - 新增
post-loop.html:统一 3 个列表页的 memo/post 分支 - 删除死代码
partials/menu.html(未被任何模板引用) navigation.html改为渲染子菜单(原来直接丢弃)并支持菜单项 i18nfooter.html属性加引号、删除空分支
- 新增
📝 修改文件汇总:
config.tomlthemes/farallon/layouts/_default/baseof.htmlthemes/farallon/layouts/_default/single.htmlthemes/farallon/layouts/_default/_markup/render-image.htmlthemes/farallon/layouts/page/search.htmlthemes/farallon/layouts/partials/head.htmlthemes/farallon/layouts/partials/footer.htmlthemes/farallon/layouts/partials/navigation.htmlthemes/farallon/layouts/partials/profile.htmlthemes/farallon/layouts/partials/category.htmlthemes/farallon/layouts/partials/cover.html(新增)themes/farallon/layouts/partials/favicon.html(新增)themes/farallon/layouts/partials/icons/(新增:date、category、views、readtime)themes/farallon/layouts/partials/like-button.html(新增)themes/farallon/layouts/partials/toc.html(新增)themes/farallon/layouts/partials/translated-card.html(新增)themes/farallon/layouts/partials/post-loop.html(新增)themes/farallon/layouts/partials/menu.html(删除)themes/farallon/assets/ts/app.tsthemes/farallon/assets/ts/action.tsthemes/farallon/assets/ts/search.ts(新增)themes/farallon/assets/scss/modules/_categoryCard.scssthemes/farallon/assets/scss/modules/_graph.scssthemes/farallon/i18n/zh-cn.yamlthemes/farallon/i18n/en-us.yaml