Publishing Bookdown to Netlify (automagically)

I didn’t realize this until today, but Netlify isn’t just a great place to host Hugo based blogs (like this one), but it’s also a great place to host Bookdown based book content.

R Cookbook 2nd Edition Cover image

Like many R Bloggers, I like to use Blogdown to publish blog posts. But as Paul Teetor and I got near completion of R Cookbook 2nd Edition, I began to give some thought to where I would host the online version of the book. O’Reilly has worked with Paul and me to arrange to Creative Commons license the source and content related to our book, in the same way Hadley Wickham and Garrett Grolemund did with R for Data Science and Winston Chang did with R Graphics Cookbook. On a lark I tried setting up Netlify to publish our book using the bookdown::gitbook content and it was disturbingly easy to get going. Let me show you how…

First I log into my Netlify account and click on “New Site from Git”:

Netlify Step 1

Figure 1: Netlify Step 1

And since I’m using Github, I click on the Github link:

Netlify Step 2

Figure 2: Netlify Step 2

I had already set up my Netlify account to work with my Github account for use with this blog. But I gave it access only to the one repo used for this blog. So I had to click on “configure the netlify app on GitHub” to allow Netlify to have access to my repo I’m using for our book:

Netlify Step 3

Figure 3: Netlify Step 3

I had already checked all my book content (including both the source and the HTML used for the book) into the GitHub repo. So I just had to point Netlify to the _book folder because that’s where Bookdown sticks the HTML.

Netlify Step 4

Figure 4: Netlify Step 4

And because Bookdown is polite enough to create a book site using an index.html and all, Netlify just copies over the _book directory to their servers and boom web site is up and running.

And because Netlify is built on a GitHub hooks model (continuous integration), every time I check a new version of the HTML into GitHub, Netlify gets a notice from Github and then Netlify automagically updates the web content. Nothing required from me other than checking the book HTML into GitHub. This is the future I wanted, but not the future I deserve.


comments powered by Disqus