Saturday, May 1, 2010

Create ProGit epub from source

A couple a days ago, I discovered that the Book Pro Git (Expert's Voice in Software Development) is available in source form on GitHub. Browsing through the repository, I found out that there is a folder called "epub" which contains a groovy script to create an epub Version of this book. Wow, that is really great! Using groovy and some other tools to create the epub. I started to clone the repository to create my own epub version of the book.

The first run of the script didn't work well on my Mac. To be honest it failed because of the missing dependencies (markdown and the path to calibre). I didn't want to download markdown and install it for this one time use. I decided to have a look into the script and find a different solution.

The creation of the epub is basically running in three steps:
  1. Convert all Files from the given language directory and fix the links to the figures. Convert the files afterwards into HTML by using markdown. Write the file to the target directory
  2. Merge all files from the target directory into one big HTML file
  3. Call calibre's ebook-convert and create the epub out of it

I made some modifications to the original groovy script
  • Use of markdownj instead the perl markdown implementation. I'm using groovy's @Grab annotation here to download the library on the first run of the script.
  • Make use of groovy's great Regex support and do a one-line search and replace on the whole file content
  • Added a custom CSS for the epub, to improve the layout of lists in the epub
  • Reduced the overall LOC by removing unnecessary code
Now the solution looks like this (it's not perfect, but it works fine for me)

Running the script created now the epub that I can now read on my nook.

You can find the new version here.

One last thing to say: Even if this book has been made available freely by the Author and the Publisher, I recommend buying the printed version to support this kind of generosity. Let the epub Version of this great book be wonderful extra of the printed Book.

No comments: