Thursday, August 4, 2011

Revisiting ePub and Mobi in Git-Scribe

‹prev | My Chain | next›

Before continuing to pick away at various niggling issues with the mobi spit out by git-scribe, I would like to take some time to investigate alternate approaches to generating the mobi.

Currently, git-scribe uses the asciidoc command to output HTML. It then manually builds wrapper HTML to mark chapters, build a table of contents and perform various other housekeeping work. The asciidoc toolchain is only capable of producing things like PDF, epub and docbook XML, not mobi proper.

The kindlegen command from Amazon, which git-scribe uses to produce mobi, support the following options:
$ kindlegen

* kindlegen(Linux) V1.2 build 33307 *
* A command line e-book compiler *
* Copyright 2011 *

Usage : kindlegen filename.opf/.htm/.html/.epub [-c0 or -c1 or c2] [-verbose] [-rebuild] [-onlydeps or -nodeps] [-western] [-o ]
-c0: no compression
-c1: standard DOC compression
-c2: Kindle huffdic compression
-o : Specifies the output file name. Output file will be created in the same directory as that of input file. should not contain directory path.
-verbose: verbose output
-rebuild: rebuilds all dependencies
-onlydeps: build only needed dependencies
-nodeps: do not check/build dependencies
-western: force build of Windows-1252 book
-releasenotes: display release notes
-gif: images are converted to GIF format (no JPEG in the book)
So, if I can get a decent epub version of SPDY Book, maybe I can generate a nicer mobi from that. Unfortunately, the epub produced by git-scribe looks like this (in calibre):

For SPDY Book, I found that the best PDF was produced by generating docbook and then running that through xsl-fo. I did not do any such tweaking for epub. Unfortunately, the xsl-fo stuff does not generate epub either. So how am I to get a cover and other useful stuff in there?

Ooh! The asciidoc web site actually has a relatively nice example of doing something like that. If I follow correctly, something along the lines of the following ought to work:
a2x -f epub -d book -a docinfo book.asc -v
With the following used as the docbook manifest (book-docinfo.xml):
<mediaobject role="cover">
<imagedata fileref="images/cover.jpg" format="JPG"/>
<textobject><phrase>The SPDY Book</phrase></textobject>
And indeed, that seems to work. The cover image is showing up along with my book in calibre:

Even better, the table of contents and formatting seems pretty nice:

I cannot believe that it actually kinda sorta works. I will go back tomorrow to start incorporating some of this in git-scribe. And I still need to figure out how well this translates into mobi.

Day #104

No comments:

Post a Comment