Posted on by & filed under ebooks, tools.

I wrote these to automate a really common task: zip up an ePub (properly) and validate it. It expects a local install of epubcheck.

Install these functions in your .bash_profile. This should work on any Unix-like system including OS X.

Zip up an ePub file

function epub()
{
rm -f $@; zip -q0X $@ mimetype; zip -qXr9D $@ *
}

Call this as:

$ epub my-book.epub

from the directory where the resources are (meaning, the should be at least a mimetype and META-INF in the current working directory). The actual arguments were taken from Bob DuCharme’s great post on creating .epub files with simple tools.

Validate an ePub file

function epubcheck()
{
java -jar /path/to/epubcheck.jar $@
}
$ epubcheck my-book.epub 
Epubcheck Version 1.0.3

No errors or warnings detected

$ epubcheck my-book.epub 
Epubcheck Version 1.0.3

ERROR: malformed.epub: OPF file OEBPS/content.opf is missing

Check finished with warnings or errors!

And then I like a shortcut that does both at once:

function ev() 
{
epub $@; epubcheck $@
}

Tomorrow I’ll show how to do the same thing even if you encounter errors running epubcheck locally, using the newly-available ePub validation API.

Tags:

Comments are closed.