kindlerb is a Ruby Kindle periodical-format ebook generator. This tool was initially extracted from kindlefeeder.com. Kindlefodder was also built on top of kindlerb.
kindlerb converts a file tree of sections, articles, images, and metadata into
a MOBI periodical-formatted document for the Kindle. It is a wrapper around the
kindlegen
program from Amazon that hides the details for templating OPF and NCX
files.
- Ruby >= 2.0.0
Add gem 'kindlerb', github: 'danchoi/kindlerb'
to your Gemfile then run
bundle install
bundle binstubs kindlerb
Then cd into your app root and then run the below command - this will install the required Kindlegen package:
./bin/setupkindlerb
You're good to go!
OR
run gem install kindlerb
Then cd into your app root and then run the below command - this will install the required Kindlegen package:
setupkindlerb
You're good to go!
Require kindlerb in your project.
require 'kindlerb'
Only the first argument is mandatory, everything else will use default values if no arguments are provided.
target_dir = Put the directory that contains your ebook files
verbose = true or false. Default is false.
compression_method = 'c0' (no compression) OR 'c1' (standard DOC compression) OR 'c2' (Kindle huffdic compression). Default is 'c2'.
The output will be a mobi document.
target_dir should include the below files and structure:
_document.yml
sections/
000/
_section.txt # contains section title
000.html # an article
001.html
001/
_section.txt
000.html
001.html
002.html
kindlerb will extract article titles from the <title>
(in <head>
) tag in
the *.html files .
The _document.yml is a YAML document. It should look like something like this:
---
doc_uuid: kindlerb.21395-2011-12-19
title: my-ebook
author: my-ebook
publisher: me
subject: News
date: "2011-12-19"
masthead: /home/choi/Desktop/masthead.gif
cover: /home/choi/Desktop/cover.gif
mobi_outfile: my-ebook.mobi
kindlerb uses the the file tree and _document.yml to construct these additional
resource required by Amazon's kindlegen
program:
- nav-contents.ncx
- contents.html
- kindlerb.opf
After that, kindlerb will exec the kindlegen program to generate your mobi document. The filename the output document is specified by the 'mobi_outfile' value in _document.yml.
Will return the full path to the Kindlegen executable file.
This is called when you first install the gem and call setupkindlerb
executable. It downloads the appropriate Kindlegen version for the host OS. There should be no need to call this after initial set up.
kindlerb will incorporate images into the generated ebook by parsing all the
src
attributes of all the <img>
tags in your *.html files.
The src
attributes must point to image files on the local filesystem. If the
paths are relative, they should be relative to the target file tree root.
Make sure all your textual source files are encoded in UTF-8.
Daniel Choi
- email: [email protected]
- github: [danchoi][github]
- twitter: @danchoi [github]:http://github.com/danchoi
Emir Aydin
- email: [email protected]
- github: [emiraydin][github]
- twitter: @emiraydin [github]:http://github.com/emiraydin
Indebted to mhl for writing the guardian-for-kindle MOBI generator in Python. kindlerb ported a bunch of ideas from that project over to Ruby.