Skip to content
Kindle periodical format ebook generation tool
Ruby HTML
Branch: master
Clone or download
emiraydin Merge pull request #10 from emiraydin/master
Fixed download issue in Linux
Latest commit 56f90d0 Mar 2, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Use system kindlegen when available; Add VERSION constant Dec 13, 2016
lib
templates This makes cover image display, fixing bug Dec 1, 2012
.gitignore more notes Jan 8, 2012
Gemfile opf mustache Jan 9, 2012
MIT-LICENSE.txt
README.md Update README.md Jan 20, 2015
Rakefile clean up Rakefile Jan 10, 2012
_document.yml.sample prepare for upload to github Jan 9, 2012
kindlerb.gemspec Use system kindlegen when available; Add VERSION constant Dec 13, 2016

README.md

kindlerb

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.

Requirements

  • Ruby >= 2.0.0

Installation and Setup

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!

How to use it

Require kindlerb in your project.

require 'kindlerb'

Kindlerb.run(target_dir, verbose, compression_method)

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.

Kindlerb.executable

Will return the full path to the Kindlegen executable file.

Kindlerb.download

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.

Images

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.

Encoding

Make sure all your textual source files are encoded in UTF-8.

Authors

Daniel Choi

Emir Aydin

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.

You can’t perform that action at this time.