Sunday, December 25, 2011

Post-Mobi Clean-up in Git-Scribe

‹prev | My Chain | next›

Running the mobi generated by git-scribe through a Calibre command-line conversion now seems like a useful thing. The resultant mobi is an "EBOK" ebook (rather than a "PDOC" personal document) which works better on some Kindles. I believe that I have resolved any display issues from the resultant Calibre mobi, so there is no reason not to use it.

No reason not to switch to it save that Calibre's command line options do not include the "EBOK" setting. Rather, it needs to be configure via the GUI. That is a not a recipe for a successful pull request back to upstream.

I think, for now, that I will introduce a post-mobi build step to the mobi generation. In my fork of git-scribe, I alter the do_mobi to optionally execute a shell script if present in the current working directory:
   def do_mobi
      return true if @done['mobi']

      do_epub

      info "GENERATING MOBI"

      decorate_epub_for_mobi

      cmd = "kindlegen -verbose book_for_mobi.epub -o book.mobi"
      return false unless ex(cmd)

      cmd = @wd +  '/scripts/post-mobi.sh'
      if File.exists?(cmd) && File.executable?(cmd)
        return false unless ex(cmd)
      end

      @done['mobi'] = true
    end
I rebuild the gem and install it:
➜  git-scribe git:(master) ✗ gem build git-scribe.gemspec  
...
➜  git-scribe git:(master) ✗ gem install git-scribe-0.0.9.gem
Successfully installed git-scribe-0.0.9
1 gem installed
Then, in the Recipes with Backbone source, I create scripts/post-mobi.sh to include:
#!/bin/sh

echo "doing post mobi things..."
ebook-convert book.mobi book_ebok.mobi --chapter-mark=none --page-breaks-before='/'
echo "done!"
Now, when I run git scribe gen mobi, I see entirely too much output (from git-scribe, from the dependent kindlegen tool and from Calibre's ebook-convert, but in there, I do see my local script echo statements:
➜  backbone-recipes git:(master) ✗ git-scribe gen mobi
...
doing post mobi things...
Converting input to HTML...
InputFormatPlugin: MOBI Input running
on /home/cstrom/repos/backbone-recipes/output/book.mobi
Parsing all content...
Forcing Recipes_with_Backbone.html into XHTML namespace
34% Running transforms on ebook... 
Merging user specified metadata... 
Detecting structure...
        Detected chapter: Chapter 1. Namespacing
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Trimming 'images/00002.jpg' from manifest
Creating MOBI Output...
67% Creating MOBI Output
Generating in-line TOC...
Applying case-transforming CSS...  
Rasterizing SVG images...
Converting XHTML to Mobipocket markup...
Serializing markup content...
  Compressing markup content...
Generating flat CTOC ...
  CNCX utilization: 1 record, 0% full
Indexing navPoints ...
Generating INDX ...
Serializing images...
MOBI output written to /home/cstrom/repos/backbone-recipes/output/book_ebok.mobi
Output saved to   /home/cstrom/repos/backbone-recipes/output/book_ebok.mobi
done!
That will do to clean up my personal toolchain. Unfortunately, I am getting further and further away from the upstream version of git-scribe. I think tomorrow I shall have a look to see what it would take to get me back on track.

Day #245

No comments:

Post a Comment