From 7a3c2d9a9f610f58b59bccadf913ed88e7ed2340 Mon Sep 17 00:00:00 2001 From: xiamuceer Date: Tue, 24 Mar 2026 11:29:09 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E6=96=B0=E5=AF=BC=E5=87=BAT?= =?UTF-8?q?XT=E5=86=85=E5=AE=B9=E6=A0=BC=E5=BC=8F=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=8B=86=E4=B9=A6=E5=AF=BC=E5=85=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/projects.py | 58 ++++++++++++------------------- frontend/src/pages/BookImport.tsx | 25 +++++++++++++ 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/backend/app/api/projects.py b/backend/app/api/projects.py index 3fc5848..23098fe 100644 --- a/backend/app/api/projects.py +++ b/backend/app/api/projects.py @@ -351,7 +351,7 @@ async def export_project_chapters( ): """ 导出项目的所有章节内容为TXT文本文件 - 按章节顺序组织,包含项目基本信息 + 按章节顺序组织,使用便于再次拆书导入的纯章节格式 """ try: # 从认证中间件获取用户ID @@ -388,46 +388,32 @@ async def export_project_chapters( txt_content = [] - txt_content.append("=" * 80) - txt_content.append(f"项目标题: {project.title}") - txt_content.append("=" * 80) - - if project.description: - txt_content.append(f"\n简介: {project.description}\n") - - if project.theme: - txt_content.append(f"主题: {project.theme}") - - if project.genre: - txt_content.append(f"类型: {project.genre}") - - txt_content.append(f"总章节数: {len(chapters)}") - txt_content.append(f"总字数: {project.current_words}") - txt_content.append("\n" + "=" * 80 + "\n\n") - - for chapter in chapters: - # 只显示主章节号,不显示子索引 - txt_content.append(f"第 {chapter.chapter_number} 章 {chapter.title}") - txt_content.append("-" * 80) - txt_content.append("") # 空行 - - if chapter.content: - txt_content.append(chapter.content) + for idx, chapter in enumerate(chapters): + chapter_title = (chapter.title or "").strip() or f"未命名章节{chapter.chapter_number}" + raw_content = (chapter.content or "").strip() + if raw_content: + formatted_lines = [] + for line in raw_content.splitlines(): + stripped_line = line.strip() + if stripped_line: + formatted_lines.append(f"  {stripped_line}") + else: + formatted_lines.append("") + chapter_content = "\n".join(formatted_lines) else: - txt_content.append("(本章暂无内容)") + chapter_content = "  (本章暂无内容)" - txt_content.append("\n\n" + "=" * 80 + "\n\n") - - txt_content.append(f"--- 全文完 ---") - - # 获取当前时间 - from datetime import datetime - export_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - txt_content.append(f"\n导出时间: {export_time}") + # 使用拆书强匹配可稳定识别的章节标题格式:第X章 标题 + txt_content.append(f"第{chapter.chapter_number}章 {chapter_title}") + txt_content.append(chapter_content) + + # 章节之间只保留一个空行,避免装饰性分割线干扰拆书识别 + if idx < len(chapters) - 1: + txt_content.append("") final_content = "\n".join(txt_content) - safe_title = "".join(c for c in project.title if c.isalnum() or c in (' ', '-', '_', ',', '。', '、')) + safe_title = "".join(c for c in (project.title or "未命名项目") if c.isalnum() or c in (' ', '-', '_', ',', '。', '、')) filename = f"{safe_title}.txt" from urllib.parse import quote diff --git a/frontend/src/pages/BookImport.tsx b/frontend/src/pages/BookImport.tsx index cb5b0e7..6adcc51 100644 --- a/frontend/src/pages/BookImport.tsx +++ b/frontend/src/pages/BookImport.tsx @@ -688,6 +688,31 @@ export default function BookImport() {

首版仅支持 .txt,建议不超过 50MB

+ +
1. 仅支持 .txt 文件,建议每章使用单独的章节标题行。
+
2. 推荐格式:第1章 标题,下一行开始写正文内容。
+
3. 正文建议按自然段换行,首行可缩进两个字符。
+
4. 章节之间保留空行即可,不要添加多余的分割线、全文完、导出时间等干扰内容。
+
+ 示例: +
+{`第1章 初入江湖
+这里是第1章正文第一段。
+这里是第1章正文第二段。
+
+第2章 雨夜追踪
+这里是第2章正文内容。`}
+                  
+
+ + } + /> +