A way you can use the kindlegen() function manually is the following:
- Install Kindlegen (which is a free command line tool from Amazon to convert .epub into .mobi).
- Add the path of Kindlegen to the PATH environment variable.
- Run R studio, build the .epub version (Build panel (upper right part by default) >
Build book > bookdown::epub_book (depending on your _output.yml configuration)).
- After you already have the epub version, in the Console panel (lower left part by default), run
bookdown::kindlegen().
Kindlegen will figure out where to find the .epub version, and convert it to .mobi.
To add this to the build process, your _build.sh could look something like this (note the last line):
#!/bin/sh
set -ev
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::html_book')"
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book')"
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::epub_book')"
Rscript -e "bookdown::kindlegen()"
And your _output.yml needs to define config for html_book, pdf_book, epub_book, like this:
bookdown::html_book:
toc: yes
css: style.css
split_by: chapter
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
template: null
bookdown::epub_book: default
After this, Build book > All formats should produce all HTML, PDF, EPUB and MOBI formats.