From 5b8b982016729d005ca09925a6925a111a35d092 Mon Sep 17 00:00:00 2001 From: Cowork 3P Date: Fri, 22 May 2026 16:15:46 +0000 Subject: [PATCH] fix(export): add EpubNav and debug logging for EPUB export (#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 --- application/core/services/export_service.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/application/core/services/export_service.py b/application/core/services/export_service.py index c12f2118a..e606a9fd0 100644 --- a/application/core/services/export_service.py +++ b/application/core/services/export_service.py @@ -92,6 +92,11 @@ def export_novel(self, novel_id: str, format: str) -> Tuple[bytes, str, str]: chapters = self.chapter_repository.list_by_novel(NovelId(novel_id)) chapters.sort(key=lambda x: x.number) logger.info("导出: %s, 章节数 %s", novel.title, len(chapters)) + # ★ 修复 #143:记录每章内容长度,便于排查导出内容为空的问题 + for ch_debug in chapters: + ch_len = len(ch_debug.content or "") + if ch_len == 0: + logger.warning("导出警告: 章节 %d (%s) 内容为空", ch_debug.number, ch_debug.title or "无标题") if format == "epub": result = self._export_to_epub(novel, chapters) elif format == "pdf": @@ -192,7 +197,9 @@ def _export_to_epub(self, novel: Novel, chapters: list[Chapter]) -> Tuple[bytes, book.toc = tuple([intro] + spine_items[1:]) book.add_item(epub.EpubNcx()) - # 不使用空 EpubNav(ebooklib 生成 nav 时会解析正文,空文档会触发 lxml Document is empty) + # ★ 修复 #143:添加 EpubNav 导航文档(EPUB 3 标准要求) + # 缺失 nav 文档会导致部分阅读器只显示目录而无法加载正文内容 + book.add_item(epub.EpubNav()) book.spine = spine_items tmp_path: Optional[str] = None