首页
/ EPUB Boilerplate 开源项目教程

EPUB Boilerplate 开源项目教程

2024-08-20 13:20:04作者:郜逊炳

1. 项目的目录结构及介绍

EPUB Boilerplate 项目的目录结构如下:

epub-boilerplate/
├── css/
│   └── style.css
├── images/
│   └── cover.jpg
├── mimetype
├── META-INF/
│   └── container.xml
├── OEBPS/
│   ├── content.opf
│   ├── toc.ncx
│   └── Text/
│       ├── chapter1.xhtml
│       ├── chapter2.xhtml
│       └── ...
└── mimetype

目录结构介绍

  • css/: 包含样式文件 style.css,用于定义 EPUB 文件的样式。
  • images/: 包含封面图片 cover.jpg
  • mimetype: 定义 EPUB 文件的 MIME 类型。
  • META-INF/: 包含 container.xml 文件,用于指定 EPUB 文件的根文件路径。
  • OEBPS/: 包含 EPUB 文件的主要内容:
    • content.opf: 描述 EPUB 文件的元数据和内容。
    • toc.ncx: 定义 EPUB 文件的目录结构。
    • Text/: 包含 EPUB 文件的文本内容,如 chapter1.xhtmlchapter2.xhtml 等。

2. 项目的启动文件介绍

EPUB Boilerplate 项目的启动文件是 content.opf。这个文件是 EPUB 文件的核心,包含了 EPUB 文件的元数据、文件列表和 spine(阅读顺序)。

content.opf 文件介绍

<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="BookId">
    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
        <dc:title>EPUB Boilerplate</dc:title>
        <dc:creator opf:role="aut">Javier Arce</dc:creator>
        <dc:identifier id="BookId">urn:uuid:12345678-9abc-def0-1234-56789abcdef0</dc:identifier>
        <dc:language>en</dc:language>
        <meta name="cover" content="cover-image"/>
    </metadata>
    <manifest>
        <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
        <item id="cover" href="Text/cover.xhtml" media-type="application/xhtml+xml"/>
        <item id="style" href="css/style.css" media-type="text/css"/>
        <item id="cover-image" href="images/cover.jpg" media-type="image/jpeg"/>
        <item id="chapter1" href="Text/chapter1.xhtml" media-type="application/xhtml+xml"/>
        <item id="chapter2" href="Text/chapter2.xhtml" media-type="application/xhtml+xml"/>
        <!-- 其他章节文件 -->
    </manifest>
    <spine toc="ncx">
        <itemref idref="cover"/>
        <itemref idref="chapter1"/>
        <itemref idref="chapter2"/>
        <!-- 其他章节文件 -->
    </spine>
    <guide>
        <reference type="cover" title="Cover" href="Text/cover.xhtml"/>
    </guide>
</package>

关键部分解释

  • metadata: 包含 EPUB 文件的元数据,如标题、作者、标识符和语言。
  • manifest: 列出 EPUB 文件中包含的所有文件。
  • spine: 定义 EPUB 文件的阅读顺序。
  • guide: 提供 EPUB 文件的导航参考。

3. 项目的配置文件介绍

EPUB Boilerplate 项目的主要配置文件是 container.xmltoc.ncx

container.xml 文件介绍

container.xml 文件位于 META-INF 目录下

登录后查看全文
热门项目推荐