Skip to content

feat: 完善站内搜索、索引校验与折叠侧栏 - #46

Merged
LeoninCS merged 4 commits into
LeoninCS:mainfrom
4evour:codex/improve-search-and-index-check
Aug 5, 2026
Merged

feat: 完善站内搜索、索引校验与折叠侧栏#46
LeoninCS merged 4 commits into
LeoninCS:mainfrom
4evour:codex/improve-search-and-index-check

Conversation

@4evour

@4evour 4evour commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

说明

这是与 #44 分离的第二个 PR。本 PR 不包含 #44 中的博客卡片 URL 换行和侧栏按钮层级调整,建议先合并 #44,以获得完整的侧栏显示修复。

改动概览

本 PR 完善站内搜索、栏目筛选和搜索索引覆盖检查,同时优化折叠侧栏的隐藏布局,并补充一条缺失的每日一问答案。

主要改动

站内搜索

  • 建立包含标题、别名、栏目、摘要、标题层级、正文和日期等字段的搜索索引。
  • 优化搜索弹层、结果摘要、高亮、排序、滚动加载和状态恢复。
  • 增加“全部、面试真题、八股总结、资源荟萃、技术博客、配套文章、项目学习”栏目筛选按钮。
  • 统一索引记录的栏目字段;栏目按钮只过滤结果,不改变现有 Fuse.js 搜索和排序逻辑。
  • 刷新页面后保留检索词、所选栏目和结果状态。
  • 为栏目筛选增加明确的结果数量与无结果提示。

搜索索引校验

  • 新增无第三方运行时依赖的 scripts/check_search_index.py
  • 检查所有应收录的已发布内容是否进入搜索索引。
  • 校验栏目名称、重复链接、生成页面和标题锚点。
  • 将索引检查接入 PR、GitHub Pages 部署和每日一问同步工作流。
  • 新增内容漏收录时,CI 会失败并指出对应页面。

折叠侧栏

  • 折叠时隐藏访问统计、品牌文字、主题按钮、搜索框和导航菜单,避免这些元素继续参与窄侧栏布局。
  • 折叠状态只保留居中的 GC 标识和展开按钮。
  • 展开后恢复访问统计、主题按钮、搜索框和导航菜单。

内容补充

  • 补充 2026.03.30 每日一问“自旋锁和互斥锁的区别”的回答。
  • 回答覆盖等待方式、CPU 消耗、上下文切换成本和适用场景。

用户影响

  • 用户可以输入关键词后按栏目缩小搜索范围。
  • 新增内容漏收录能够在合并或部署前被发现。
  • 折叠侧栏不再显示被压缩、裁切的统计数据和隐藏控件。
  • 不更换当前搜索引擎,也不引入新的前端运行时依赖。

验证

  • hugo --minify 构建通过,共生成 439 个页面。
  • python scripts/check_search_index.py --site public 通过:469 条索引记录,覆盖 402 个内容页面。
  • ruff checkruff format --check 通过。
  • 搜索脚本的 Oxlint correctness / suspicious 检查通过。
  • 浏览器验证“MySQL + 技术博客”栏目筛选返回 5 条结果。
  • 浏览器验证折叠侧栏隐藏状态正确,页面没有横向溢出。
  • 浏览器控制台无错误。

@4evour

4evour commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Uploading image.png…
大致效果

@LeoninCS
LeoninCS marked this pull request as ready for review August 4, 2026 16:29
Copilot AI lite review requested due to automatic review settings August 4, 2026 16:29
@LeoninCS

LeoninCS commented Aug 4, 2026

Copy link
Copy Markdown
Owner

@copilot 请修复此拉取请求中的合并冲突。

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 面向 GoClub(Hugo 静态站点)完善站内搜索能力(索引字段、筛选、状态恢复与高亮)、新增搜索索引覆盖校验脚本并接入 CI,同时优化侧栏折叠/可调宽度交互,并补充一条“每日一问”内容。

Changes:

  • 新增搜索索引覆盖校验脚本 scripts/check_search_index.py,并在 PR/部署/每日同步工作流中强制校验。
  • 重做/增强搜索前端:新增索引模板 assets/search-data.json、搜索逻辑 assets/search.js、搜索 UI 样式与交互(筛选、摘要、高亮、滚动加载、状态恢复等)。
  • 侧栏新增可拖拽调宽(含键盘操作),折叠时隐藏更多侧栏内部元素;并补充每日一问 2026.03.30 答案。

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/check_search_index.py 新增索引覆盖/重复/栏目/锚点校验脚本,用于 CI 兜底发现漏收录与坏链接。
layouts/partials/docs/inject/body.html 侧栏折叠/宽度持久化与拖拽调宽交互逻辑。
layouts/baseof.html 侧栏结构中加入可拖拽调宽的 resizer 元素。
layouts/_partials/docs/search.html 新增搜索弹层与栏目筛选按钮 DOM(但当前路径疑似无法被 Hugo partial 解析命中)。
content/docs/baguwen/每日一问.md 补充 2026.03.30 “自旋锁和互斥锁的区别”答案。
assets/search.js 新增/增强 Fuse 搜索逻辑:筛选、排序、摘要、高亮、滚动加载、状态恢复等。
assets/search-data.json 新增搜索索引生成模板,补充栏目/type/headings/content 等字段。
assets/_custom.scss 新增搜索弹层/筛选/高亮样式与侧栏折叠隐藏逻辑、resizer 样式。
.github/workflows/static.yml 部署工作流增加索引覆盖校验步骤。
.github/workflows/pr-check.yml PR 检查增加索引覆盖校验步骤。
.github/workflows/daily-question-sync.yml 每日同步后增加索引覆盖校验步骤。

Comment thread layouts/partials/docs/inject/body.html Outdated
var tocControl = document.getElementById("toc-control");
var minWidth = 272;
var maxWidth = 520;
var defaultWidth = parseFloat(getComputedStyle(root).getPropertyValue("--goclub-sidebar-width")) || 288;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新提交已修复该问题

Comment on lines +1 to +4
{{ if default true .Site.Params.BookSearch }}
<div class="book-search hidden">
<div class="book-search-topbar">
<div>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

验证结果表明第二条建议的前提不成立:项目使用 Hugo 0.159.0,主题最低要求 0.158.0.
主题自身和项目覆盖都使用 layouts/_partials;partial "docs/search" 正是从该路径加载。移动到 layouts/partials 会偏离当前 Hugo 模板体系。

@4evour

4evour commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

冲突已解决,可以安全合并了 @LeoninCS

@LeoninCS
LeoninCS merged commit 23b240c into LeoninCS:main Aug 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants