Cahcn的资料库
Other 6 分钟阅读

更换站点主题

目录

用腻了之前的主题,况且之前使用的主题由日本人开发,显示的字体非简体中文字形,看起来别扭。

更换为 Farallon主题 ,借助 ChatGPT 5.4、5.3-codex 与 GLM 5.2,修改了主题的样式和功能,使其更适合笔者的需求。


改动如下:

🚀 新特性

1. 站点图标与 SEO 元信息增强

  • 文件themes/farallon/layouts/partials/head.htmlpartials/favicon.html(新增)、partials/cover.html(新增)
  • 说明
    • 新增 params.favicon 配置项,支持本地资源路径、远程 URL 与 assets 资源
    • favicon 解析逻辑提取为 partials/favicon.html,仅输出单一 <link rel="icon">,默认回退到主题内置 favicon.png
    • 移除 vnd.microsoft.icon MIME 强制绑定与冗余的 shortcut icon
    • head.html 重写完善 SEO:新增 <link rel="canonical">og:image / twitter:image(复用封面提取逻辑)、og:site_namearticle:published_time
    • og 标签覆盖所有页面类型(原来仅文章页有),首页输出 og:type=website、文章页输出 article
    • 移除过时的 X-UA-Compatible 与重复 RSS feed 链接

2. 配置项与显示控制重构

  • 文件config.tomlthemes/farallon/layouts/partials/profile.htmllayouts/_default/baseof.html
  • 说明
    • 新增 showSiteDescriptionshowAuthorDescription 开关,分别控制站点描述与作者描述显示,默认关闭
    • DEFAULT_THEME 增加 auto 兜底,未配置时不再写入空值
    • 移除已失效的 showAuthor 配置项(文章作者卡片已整体移除,详见第 4 条)

🎨 样式与界面优化

3. 分类模块视觉优化

  • 文件themes/farallon/layouts/partials/category.htmlassets/scss/modules/_categoryCard.scss
  • 说明
    • 增加“分类”标签标题,提升语义清晰度
    • 描述文本改为有值才渲染,避免空行占位
    • 分类项样式从分割线列表改为轻量卡片:缩小内边距与封面尺寸、降低标题字号字重、hover 用浅背景细边框、描述限两行截断

4. 界面元素精简

  • 文件themes/farallon/layouts/partials/profile.htmllayouts/_default/single.htmlconfig.toml
  • 说明
    • 移除首页 fWidgetAuthor--name 作者名元素
    • 移除文章末尾整个作者卡片(fAuthorfAuthor--namefAuthor--descriptionfAuthor--icons 及头像),避免 authorAvatar 未配置时 src="" 的显示问题
    • 清理 config.toml 中已失效的 showAuthor 配置项

5. 代码块行号排版修复

  • 文件themes/farallon/assets/scss/modules/_graph.scss
  • 说明
    • 修复因缺少 Hugo Chroma 专用样式导致的代码块行号错位
    • .highlight pre 恢复 white-space: preoverflow-x: auto
    • .highlight code 移除内联代码背景与 padding,防止双重样式叠加
    • .line 设置 display: block;为 .ln 设置固定宽度、右对齐与灰色字体,稳定行号列对齐

🐛 问题修复

6. 模板 Bug 修复

  • 文件themes/farallon/layouts/_default/baseof.htmllayouts/page/search.htmllayouts/partials/category.html
  • 说明
    • 修复 <html lang> 属性在未配置 languageCode 时输出前导空格(lang=" en"
    • 移除空的 <body class="">
    • 删除搜索页重复渲染的 #searchbox 容器
    • 修复 category.htmlwith 块内访问 .Params.description 的字段错误(分类配置 description 时必崩的隐藏 bug)

7. JS 运行时错误修复

  • 文件themes/farallon/assets/ts/app.tsassets/ts/action.ts
  • 说明
    • app.tsinitSearch 加空值守卫:search=false 时不渲染搜索图标,避免 null.addEventListener 报错
    • action.tsactionDomain 未配置时跳过所有后端请求(点赞、阅读量等),避免向站点自身发起 /post/views 404 请求

⚡ 性能与代码质量

8. 性能优化

  • 文件themes/farallon/layouts/_default/_markup/render-image.htmllayouts/page/search.htmllayouts/partials/footer.htmlassets/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.htmllayouts/partials/footer.html
  • 说明
    • 新增 cover.html:统一 4 处重复的封面提取正则
    • 新增 favicon.html:统一 2 处重复的 favicon 解析逻辑
    • 新增 icons/(date / category / views / readtime):替换 3 个文件中重复的长 SVG
    • 新增 like-button.htmltoc.htmltranslated-card.html:替换两个 single 模板的重复块
    • 新增 post-loop.html:统一 3 个列表页的 memo/post 分支
    • 删除死代码 partials/menu.html(未被任何模板引用)
    • navigation.html 改为渲染子菜单(原来直接丢弃)并支持菜单项 i18n
    • footer.html 属性加引号、删除空分支

📝 修改文件汇总:

  • config.toml
  • themes/farallon/layouts/_default/baseof.html
  • themes/farallon/layouts/_default/single.html
  • themes/farallon/layouts/_default/_markup/render-image.html
  • themes/farallon/layouts/page/search.html
  • themes/farallon/layouts/partials/head.html
  • themes/farallon/layouts/partials/footer.html
  • themes/farallon/layouts/partials/navigation.html
  • themes/farallon/layouts/partials/profile.html
  • themes/farallon/layouts/partials/category.html
  • themes/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.ts
  • themes/farallon/assets/ts/action.ts
  • themes/farallon/assets/ts/search.ts(新增)
  • themes/farallon/assets/scss/modules/_categoryCard.scss
  • themes/farallon/assets/scss/modules/_graph.scss
  • themes/farallon/i18n/zh-cn.yaml
  • themes/farallon/i18n/en-us.yaml
分类
Other