Skip to content

fix(docs): 修复 Docsify 章节子侧边栏错挂上一章目录#437

Open
puppylpg wants to merge 1 commit intodatawhalechina:mainfrom
puppylpg:fix/docsify-sidebar-toc-chapter-mismatch
Open

fix(docs): 修复 Docsify 章节子侧边栏错挂上一章目录#437
puppylpg wants to merge 1 commit intodatawhalechina:mainfrom
puppylpg:fix/docsify-sidebar-toc-chapter-mismatch

Conversation

@puppylpg
Copy link
Copy Markdown

@puppylpg puppylpg commented Mar 23, 2026

问题

从其他章节(例如第七章)切换到第六章时,左侧子目录仍显示上一章的小节编号(如 7.1、7.2),与当前页「第六章」不一致。
image

原因

Docsify 的 subMaxLevel 子侧边栏依赖 compiler.toccacheTree[path],在页面切换时可能未与当前文档对齐。

修改

hook.beforeEach 中于新页编译前调用 resetToc(),并删除当前路径下的 cacheTree 缓存项,强制按当前页标题重新生成子侧边栏。

修改文件:docs/index.html

在 beforeEach 中重置 compiler.toc 并清除当前路径的 cacheTree 缓存,
避免从第七章等页面切换后,第六章下仍显示 7.1、7.2 等小节标题。

Made-with: Cursor
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.

1 participant