A lightweight boilerplate for self-publishing ebooks with markdown and command line. The ebook boilerplate transforms markdown files into PDF, EPUB, MOBI, and HTML files, and provides a zipped version with all four.
Note: This works in MacOS, but has not been tested in Windows. At a minimum, the
zip command will not work and will need to be set to
Make sure these are installed first.
In bash/terminal/command line,
cd into your project directory. Then run:
This will create your ebook files from your markdown files and assets.
- Add your book title, subtitle, author info, and so on to the
title.mdfiles in the
assetsdirectory. Fields that you need to update are in ALL CAPS so that you can easily find them.
- Save your book content as markdown files in the
chaptersdirectory. I recommend prefixing chapter names with numbers to order them.
- Book assets---CSS, metadata, etc.---go in the
- Save project images in the
assets/imgdirectory (or anywhere else that makes sense for you). These should be referenced in your chapters relative to the root directory:
- If you want a cover for your PDFs, include a
cover.pdffile in the
There are two ways to configure the Ebook Boilerplate:
- Open up the
build.shfile and change the defaults.
- Pass in flags with the
# Defaults TITLE='ebook' # the title/filename EPUB='false' # if true, publish an EPUB version PDF='false' # if true, publish a PDF MOBI='false' # if true, publish a MOBI version HTML='false' # if true, public an HTML version ZIP='false' # if true, create a zip file ALL='true' # if true publish all formats (regardless of other settings) COVER='false' # if true, add a cover for the PDF version
-t 'title'- The title/filename to use for your ebooks (defaults).
-e- If enabled, generate an EPUB.
-p- If enabled, generate a PDF.
-c- If enabled, add a cover to the PDF file.
-m- If enabled, generate a MOBI file.
-h- If enabled, generate an HTML file.
-z- If enabled, generate a zip file (requires all four other file types to work).
-a- If enabled, generate all file types (defaults to
Enabling individual file types (
-h) will automatically set all file types (
sh build.sh -t 'my-awesome-ebook'
Only generate a PDF and EPUB
sh build.sh -e -p
Only generate a PDF and EPUB with a custom title
sh build.sh -t 'my-awesome-ebook' -e -p
Use a cover with your PDFs
sh build.sh -c
Quirks and Other Issues
- I use wkhtmltopdf instead of LaTeX because it lets you style PDFs with CSS, giving you much more control over how things look.
- I don't apply any CSS to the EPUB and MOBI formats. I've had better support across a wider range of ereaders by letting them just use their default styles.
- wkhtmltopdf does not add page numbers to the generated PDF, and I've yet to find a way to make it do so.
- You must include an empty line before youR
h2page-level markdown headers (ex.
## Chapter Title) or Pandoc will just skip it when creating your file. No idea why.
- Break tags (
<br/>) must include the self-closing slash (ie. don't do this:
<br>) or they'll throw an error, even though slashless is valid HTML5.
The code is available under the MIT License.