fix(docs): 修复 Docsify 章节子侧边栏错挂上一章目录#437
Open
puppylpg wants to merge 1 commit intodatawhalechina:mainfrom
Open
Conversation
在 beforeEach 中重置 compiler.toc 并清除当前路径的 cacheTree 缓存, 避免从第七章等页面切换后,第六章下仍显示 7.1、7.2 等小节标题。 Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
从其他章节(例如第七章)切换到第六章时,左侧子目录仍显示上一章的小节编号(如 7.1、7.2),与当前页「第六章」不一致。

原因
Docsify 的
subMaxLevel子侧边栏依赖compiler.toc与cacheTree[path],在页面切换时可能未与当前文档对齐。修改
在
hook.beforeEach中于新页编译前调用resetToc(),并删除当前路径下的cacheTree缓存项,强制按当前页标题重新生成子侧边栏。修改文件:
docs/index.html