Skip to content

fix(epub): 修复生成 EPUB 后目录跳转错误 - #401

Open
AldenWangExis wants to merge 2 commits into
Vonng:mainfrom
AldenWangExis:fix/epub-toc-links
Open

fix(epub): 修复生成 EPUB 后目录跳转错误#401
AldenWangExis wants to merge 2 commits into
Vonng:mainfrom
AldenWangExis:fix/epub-toc-links

Conversation

@AldenWangExis

@AldenWangExis AldenWangExis commented May 26, 2026

Copy link
Copy Markdown

我在本地用 make epub 生成 EPUB 后发现,阅读器里的目录索引跳转不正确:点击多个章节目录项时,都会跳到首页附近,而不是对应章节正文。

问题原因是 EPUB 构建时,pandoc 没有把 Hugo front matter 里的 title 当作章节标题处理;同时网站目录页里的链接标题被写入了 EPUB TOC,导致目录项指向了目录页中的链接位置。检查生成结果时还发现,Hugo 的 callout shortcode 也会原样出现在 EPUB 正文里。

本 PR 做了以下处理:

  • 预处理 Markdown 时,将 front matter 中的 title 转成真实的 H1。
  • 重写 EPUB 内部的站内链接和锚点,保证目录和正文链接能指向正确章节。
  • 避免网站目录页里的链接标题污染 EPUB TOC。
  • 将 Hugo callout shortcode 转成普通 Markdown 引用块。
  • 使用 --split-level=1 让 pandoc 按章节拆分 EPUB 正文。
  • 修正 part-iipart-iii 在 EPUB 输入列表中的顺序。

本地验证:

make epub
unzip -t output/ddia.epub

验证结果:EPUB 可以正常生成,正文已按章节拆分,目录项能跳转到对应章节,nav.xhtml 中没有缺失锚点,正文中也不再残留 Hugo shortcode。

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