How to (fully) automate .mobi file creation?

I've got a book that I'm developing on Github using Travis CI so that it rebuilds the book after every commit. I'm going to be doing this with a lot of books. I'd like to include .mobi files in the output of the build. I've got it working, except for one thing.

Right now I have to manually specify the ePub filename and location in the _build.sh file using the following command:

Rscript -e "bookdown::calibre('_book/filename.epub', 'mobi')"

This is in contrast to the command to create the epub, which is generic enough to work on any book I would create, since it starts from the main index.Rmd file:

Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::epub_book')"

Is there any way for me to get the name of the epub file programmatically and insert it into the R command so that I don't have to manually look it up and change this command for every book?

I believe render_book will return as a result value the path the book. You could use that in your other command. Like instead of doing two calls to Rscript you do one with both command ? Or use an R scripts to run in travis ?

Did you try that ?

1 Like

Thanks! Given what you said about it returning the path, I figured out how to do it on one line as follows:

Rscript -e "epubFile <- bookdown::render_book('index.Rmd', 'bookdown::epub_book'); bookdown::calibre(epubFile, 'mobi')"

Appreciate your help!

1 Like

Yes that is exactly what I thought you could do ! :+1:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.