Assignment 1 Due 3/31
Create an ePub file manually, from a long online article of your choice.
Html To xHTML
First extract the html from your source text. There are many ways to do this, but a simple way is to open the page in Firefox, select the text, right click and select “View Selection Source”.
A valid epub file is made up of xhtml (not html), so you will likely need to convert the source. WordPress has a good overview of the differences.
An easy way to do convert to xhtml is by running the source html content through the w3c HTML Tidy tool, which you can find online at http://infohound.net/tidy/
Make sure that “Output XHTML” is checked and that you only use the output from inside the body tag.
- Drop proprietary attributes
Next you will divide the text up into xhtml chapters as you see fit, but make sure the that your final epub contains at least two files.
Wrap each xhtml fragment in a document like “chapter_001.xhtml” in the template, replacing “Your Content Here” with the xhtml output.
Open Package Format
The OPF file (Open Package Format) is an XML file containing metadata about the book, the manifest and the spine.
In META-INF/container.xml there is a rootfile element that points to the opf file for the epub. In the template, the opf file is at ops/package.opf
Make sure to cite and credit the original authors in dc:title and dc:creator of the metadata element.
The manifest records all the files which make up the epub’s content. This includes xhtml files, images, fonts and stylesheets. Once you have created your chapters, you will need to add them to the manifest element in the OPF.
Add each of your xhtml file as a item in the manifest like the following:
<item id="chapter_001" href="chapter_001.xhtml" media-type="application/xhtml+xml" />
The id must be unique and the href should be a url relative to the location of the package file.
The spine defines the order the book will be read in. Each chapter gets a itemref in the spine element of the OPF.
<itemref linear="yes" idref="chapter_001"/>
The idref must correspond the the id that the chapter was given in its manifest item.
Table of Contents
This navigation file is designated in the manifest by having “nav” in the properties attribute.
<item id="toc" properties="nav" href="toc.xhtml" media-type="application/xhtml+xml"/>
In the template, the nav element is in the toc.xhtml file. The element contains an ordered list, with a li list item element containing a link to each navigation point in the book.
Add an li and a for each chapter of your book, making the href point to the filename of that chapter. Hrefs can also include fragment identifiers to link within a document (such as chapter_001.xhtml#introduction)
To Zip up the files and folders you created into an epub, you can run the following commands in the terminal:
zip -X0 "archive.epub" mimetype
zip -rDX9 "archive.epub" * -x "*.DS_Store" -x mimetype
Make sure your epub passes validation with EPUB Check: http://validator.idpf.org/
You can ignore the error:
Obsolete or irregular DOCTYPE statement. External DTD entities are not allowed. Use '' instead.
or switch the doctype in the headers of you html files to
Kindle (Extra Credit!)
Want to try your epub on a Kindle or other Amazon app?
Download the KindleGen command line tool and run your epub through it.
Open the zip file you downloaded and go to that folder in the terminal. Then run:
It will output a .mobi that you can load on your Kindle or view in the Preview application Amazon provides.
Please email me with your epub or a link to the files on github. Make sure to include your name and the assignment number in the filename. (i.e. lastname_firstname_a1.epub)