exp

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package exp 实现已完成章节的导出能力。

与 imp/ 对称:纯本地 IO,不依赖 LLM,不改 store 状态。导出可以与 Engine 并发运行(只读 Progress + 章节终稿),属于横向能力。

第一版只支持 TXT;EPUB 留待下一轮。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Store *store.Store
}

Deps 是 Run 所需依赖。仅 store;导出无需 LLM、prompt、bundle。

type Format

type Format string

Format 标识导出格式。

const (
	// FormatTXT 纯文本输出。
	FormatTXT Format = "txt"
	// FormatEPUB 标准 EPUB 3 容器(zip + xhtml)。
	FormatEPUB Format = "epub"
)

type Options

type Options struct {
	// Format 空字符串时由 OutPath 后缀推断(.txt → TXT,.epub → EPUB);
	// OutPath 也为空时回退 FormatTXT。SDK 调用方可显式指定以跳过推断。
	Format Format

	// OutPath 输出文件路径;空表示 {novelDir}/{NovelName}.{ext},
	// ext 由 Format 决定(NovelName 为空则用目录名)。
	OutPath string

	// From / To 章节范围,闭区间。0 表示从第 1 章 / 到最后一章。
	// 范围内未完成的章节会被跳过并写入 Result.Skipped,不视为错误。
	From, To int

	// Overwrite 文件存在时是否覆盖;默认拒绝。
	Overwrite bool
}

Options 控制导出行为。zero-value 等价于"导出全本到默认路径,文件存在时报错"。

版式:《书名》 → 卷分隔 → 章节正文。两类内部数据不进导出:premise(创作蓝图, 含目标读者 / 核心消费点 / 写作禁区等后台元信息,给作者与引擎看,不是读者的序); 弧分隔(读者视角下弧是过细的内部结构)。书名与卷分隔始终保留。

type Result

type Result struct {
	// Path 实际写入的文件路径(绝对或调用方传入的相对)。
	Path string
	// Chapters 实际写入的章节数。
	Chapters int
	// Bytes 文件字节数(UTF-8)。
	Bytes int
	// Skipped 落在请求范围内但未完成的章节号。
	Skipped []int
}

Result 是一次成功导出的产物摘要。

func Run

func Run(ctx context.Context, deps Deps, opts Options) (*Result, error)

Run 执行一次导出。同步返回,IO 量小(本地文件读写)。

失败语义:

  • deps/opts 非法 → 配置错误立即返回
  • 无任何已完成章节 → 返回错误(让调用方明确)
  • 范围内某章 chapters/{ch}.md 缺失 → 返回错误(progress 与文件系统不一致是事实层 bug,应让用户看见)
  • 输出路径已存在且未指定 Overwrite → 返回错误

Skipped 用于"范围内合法但尚未完成"的情况(用户传 to=100 但只写到 80)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL