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
- Ruby 1.9.x.
- Make sure kindlegen is on your PATH.
You can get kindlegen here.
gem install kindlerb
How to use it
Run the program at the root of the file tree:
kindlerb [filetree dir]
The output will be a mobi document.
You can also use the generator inside a Ruby script - you can use it two ways:
Kindlerb.run # will pack everything and generate a .mobi in the current directory Kindlerb.prepare_content(path) # build all the files required by kindlegen (opf, ncx, etc). # you can customize whatever you want here - for instance, override the 'sections.html' files, etc Kindlerb.generate_mobi(path) # generate the .mobi file.
The file tree input structure is
_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
<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
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.
kindlerb will incorporate images into the generated ebook by parsing all the
src attributes of all the
<img> tags in your *.html files.
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.