Skip to content

fix(export): add EpubNav and debug logging for EPUB export (#143)#172

Open
liaoyl830 wants to merge 1 commit into
shenminglinyi:masterfrom
liaoyl830:fix/epub-export-missing-content
Open

fix(export): add EpubNav and debug logging for EPUB export (#143)#172
liaoyl830 wants to merge 1 commit into
shenminglinyi:masterfrom
liaoyl830:fix/epub-export-missing-content

Conversation

@liaoyl830
Copy link
Copy Markdown

@liaoyl830 liaoyl830 commented May 22, 2026

变更类型

  • fix Bug 修复

变更说明

修复导出电子书(EPUB 格式)后部分阅读器只显示目录不显示章节内容的问题。

根因

生成的 EPUB 文件缺少 必需的 EpubNav 导航文档(EPUB 3 标准要求)。某些 EPUB 阅读器在缺少 nav 文档时无法正确加载正文内容,只展示目录。

修复

  1. _export_to_epub() 中添加 book.add_item(epub.EpubNav()),生成符合 EPUB 3 标准的导航文档。
  2. 添加调试日志:导出时检查并记录内容为空的章节,便于排查是否是数据库中章节内容为空导致的问题。

架构影响

  • 涉及层级:application
  • 是否修改现有 API 契约:否
  • 是否新增数据库表/字段:否

Summary by CodeRabbit

  • Bug Fixes
    • Improved EPUB export compatibility with reading apps by ensuring proper navigation structure is included.
    • Enhanced export diagnostics to identify chapters with empty content, aiding troubleshooting of export issues.

Review Change Stack

…inyi#143)

When exporting novels as EPUB, some readers only show the table of
contents without chapter content. This is because the EPUB was missing
the required EpubNav navigation document (EPUB 3 standard).

Changes:
1. Add book.add_item(epub.EpubNav()) to the EPUB export
2. Add debug logging that warns when a chapter has empty content,
   helping diagnose whether content is truly missing from the DB
@liaoyl830 liaoyl830 requested a review from shenminglinyi as a code owner May 22, 2026 16:15
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

The export service now validates chapter content during export, logging warnings for any chapters with empty content. Additionally, the EPUB generation process explicitly adds navigation metadata to the book, ensuring proper structure for EPUB 3 compliance and reader app compatibility.

Changes

Export Service Enhancements

Layer / File(s) Summary
Empty chapter detection and EPUB navigation support
application/core/services/export_service.py
export_novel iterates through chapters to compute content length and logs warnings for empty chapter content. _export_to_epub now adds an explicit EpubNav item to the book, ensuring EPUB 3 navigation metadata is included in generated output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • shenminglinyi/PlotPilot#35: This PR builds directly on export functionality introduced in #35, adding validation logging and EPUB navigation compliance to the same service methods.

Suggested reviewers

  • shenminglinyi

Poem

🐰 A rabbit hops through exports, checking every page,
"Empty chapters? Warning logged!" on wisdom's stage.
Nav metadata added, EPUB gleams so bright,
Reading apps shall smile at last—your format's right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding EpubNav and debug logging for EPUB export to fix chapter content display issues.
Description check ✅ Passed The description covers all required sections: change type, change explanation with root cause and fix details, and architecture impact assessment.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
application/core/services/export_service.py (1)

95-99: ⚡ Quick win

Use debug level for this diagnostic signal.

This check is useful for troubleshooting, but emitting it as warning can create noisy alerts in normal export flows with intentionally empty chapters. Prefer logger.debug(...) here.

Proposed change
-                if ch_len == 0:
-                    logger.warning("导出警告: 章节 %d (%s) 内容为空", ch_debug.number, ch_debug.title or "无标题")
+                if ch_len == 0:
+                    logger.debug("导出诊断: 章节 %d (%s) 内容为空", ch_debug.number, ch_debug.title or "无标题")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@application/core/services/export_service.py` around lines 95 - 99, The
logging of empty chapter content currently uses logger.warning inside the loop
over chapters (variable ch_debug) in ExportService/export_service.py which can
be noisy; change the call from logger.warning(...) to logger.debug(...) so the
diagnostic is emitted at debug level while keeping the same message and
formatting (use ch_debug.number and ch_debug.title or fallback) to preserve
context for troubleshooting. Ensure only the logging method is modified and no
other logic around ch_len calculation or the chapters iteration is altered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@application/core/services/export_service.py`:
- Around line 95-99: The logging of empty chapter content currently uses
logger.warning inside the loop over chapters (variable ch_debug) in
ExportService/export_service.py which can be noisy; change the call from
logger.warning(...) to logger.debug(...) so the diagnostic is emitted at debug
level while keeping the same message and formatting (use ch_debug.number and
ch_debug.title or fallback) to preserve context for troubleshooting. Ensure only
the logging method is modified and no other logic around ch_len calculation or
the chapters iteration is altered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a435d93-13a8-410b-bd55-1680e1c0060f

📥 Commits

Reviewing files that changed from the base of the PR and between 1008f81 and 5b8b982.

📒 Files selected for processing (1)
  • application/core/services/export_service.py

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