fix(export): add EpubNav and debug logging for EPUB export (#143)#172
fix(export): add EpubNav and debug logging for EPUB export (#143)#172liaoyl830 wants to merge 1 commit into
Conversation
…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
📝 WalkthroughWalkthroughThe 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. ChangesExport Service Enhancements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
application/core/services/export_service.py (1)
95-99: ⚡ Quick winUse debug level for this diagnostic signal.
This check is useful for troubleshooting, but emitting it as
warningcan create noisy alerts in normal export flows with intentionally empty chapters. Preferlogger.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
📒 Files selected for processing (1)
application/core/services/export_service.py
变更类型
fixBug 修复变更说明
修复导出电子书(EPUB 格式)后部分阅读器只显示目录不显示章节内容的问题。
根因
生成的 EPUB 文件缺少 必需的
EpubNav导航文档(EPUB 3 标准要求)。某些 EPUB 阅读器在缺少 nav 文档时无法正确加载正文内容,只展示目录。修复
_export_to_epub()中添加book.add_item(epub.EpubNav()),生成符合 EPUB 3 标准的导航文档。架构影响
applicationSummary by CodeRabbit