Skip to content

Commit 337effd

Browse files
committed
Add Epub.js documentation
1 parent 70424c4 commit 337effd

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

content/docs-v0/epubjs.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Creating Epubs with Epub.js
3+
weight: 5700
4+
type: essay
5+
menu: false
6+
abstract: "Using a Publication manifest and Epub.js to create Epub files"
7+
---
8+
9+
[Epub.js](https://github.com/futurepress/epub.js)is an open source library for parsing and rendering Epub files using Javascript. The [CLI for Epub.js](https://github.com/futurepress/epubjs-cli) enables creating Epub files from [W3C Publication Manifests](https://www.w3.org/TR/pub-manifest/).
10+
11+
## Publication Manifest
12+
A publication manifest is a JSON-LD serialized document that allows for expressing information about a digital publication, and providing URLs to the resource that publication requires.
13+
14+
At its simplest, the document contains:
15+
* The `@context` for the JSONn-LD document
16+
* The type of the document, which for manifest that will eventually be used to create and Epub should always be `Book`.
17+
* For Epub generation the document should include a `conformsTo` with the Epub specification url.
18+
* A unique `id` for the document.
19+
* A reading order array of HTML files that contain the publications content in the order it should be displayed.
20+
* Links to any resources that content will link to, such as stylesheets / images / fonts etc.
21+
* A `url` is also required for the manifest standard but is optional when using a manifest to convert to Epub as it will be ignored.
22+
23+
```json
24+
{
25+
"@context": [
26+
"https://schema.org",
27+
"https://www.w3.org/ns/pub-context"
28+
],
29+
"type": "Book",
30+
"conformsTo": "https://www.w3.org/publishing/epub3/",
31+
"id": "example.book.123",
32+
"readingOrder": [
33+
{
34+
"url": "content/titlepage.html",
35+
"encodingFormat": "text/html",
36+
"name": "Title Page"
37+
},
38+
...
39+
],
40+
"resources" : {
41+
{
42+
"url": "css/stylesheet.css",
43+
"encodingFormat": "text/css"
44+
}
45+
...
46+
}
47+
}
48+
49+
```
50+
51+
## Metadata
52+
The manifest can support any schema.org metadata but when converting to Epub there are a few important ones that will be included in the generated `package.opf`.
53+
54+
* `dateModified` -> `dcterms:modified`
55+
* `id` -> `dc:identifier`
56+
* `inLanguage` -> `dc:language`
57+
* `dateModified` -> `dcterms:modified`
58+
* `rights` -> `dc:rights`
59+
* `creators[]` -> `dc:creator`
60+
* `contributor[]` -> `dc:contributor`
61+
* `title` -> `dc:title`
62+
* `source` -> `dc:source`
63+
* `subject` -> `dc:subject`
64+
* `description` -> `dc:description`
65+
66+
## Reading Order
67+
Each item in the `readingOrder` array will be converted to a spine item in the epub. Any content that shouldn’t be ordered (`linear=“no”`) should be included in `resources` instead.
68+
69+
Each item should have an `url` entry containing a relative path to the items HTML file.
70+
71+
Optionally items can include a `properties` array, which will be passed as spine item properties when converting to Epub.
72+
73+
## Resources
74+
Resources should contain the `url` of all the assets that a publication will need to display, and will all be included in the output Epub zip file.
75+
76+
For example, a cover HTML page might look like:
77+
```
78+
{
79+
"url": "content/cover.html",
80+
"encodingFormat": "text/html",
81+
"rel": "cover"
82+
}
83+
```
84+
85+
The `url` entry can be relative or absolute.
86+
87+
The `encodingFormat` is the mime-type of the linked resource, including this helps to identify the type of resource but is optional as it can be inferred from the filename.
88+
89+
90+
There are a few special `rel` options to help with converting to Epub:
91+
* `cover` -> identifies the cover spine item
92+
* `cover-image` -> identifies the cover image url
93+
* `contents` -> identifies the Table of Contents / Nav for the Epub
94+
95+
## Using the Epubjs CLI
96+
Quire will output the required JSON document to convert a publication into Epub, but should any tweaks or debugging be needed it can be manually updated after building in `_epub/manifest.json`.
97+
98+
**Note:** the `manifest.json` in the `_site` folder is unrelated and used by 11ty.
99+
100+
After making any tweaks, you can re-run the Epub generation outside of Quire by using the `epubjs-cli` library directly.
101+
102+
```bash
103+
npx epubs-cli create ./_epub/manifest.json -o mybook.epub
104+
```

0 commit comments

Comments
 (0)