Getting Started
Today, we're going to look at how to host a book built with Gitbook on Netlify, including setting up continuous deployment.
This tutorial will start from scratch (if you already have Gitbook set up, you can skip down to here).
Let's get your workstation prepped (this guide assumes you have Node.js installed).
First, use mkdir
to create the gitbook
directory where you'll be working:
$ mkdir /PATH/TO/gitbook
$ cd /PATH/TO/gitbook
Now we need to create the package.json
file, which will tell Netlify how to handle your content
$ npm init
You don't have to enter any values for the questions that the above command will ask you. Just hit the enter
key for each one. The necessary info will be injected into the package.json
file with the following command:
$ npm install -g gitbook-cli --save
This will install Gitbook, and the --save
updates your package.json
file.
Now, Gitbook will set up your book for you:
$ gitbook init
In your gitbook
directory you'll now see README.md
and SUMMARY.md
. Open README.md
in your favorite text editor, and you'll see that it's ready to function as the introduction to your book. Let's add some text to it:
# Introduction
This is a book written in Gitbook and hosted with Netlify.
Let's make a few chapters for your book. Create a file called chapter1.md
and put some content in it:
# The Jabberwocky
`Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
Let's repeat that for chapter2.md
:
# A Modest Proposal
### For Preventing The Children of Poor People in Ireland From Being Aburden to Their Parents or Country, and For Making Them Beneficial to The Public
It is a melancholy object to those who walk through this great town or travel in the country, when they see the streets, the roads, and cabin doors, crowded with beggars of the female sex, followed by three, four, or six children, all in rags and importuning every passenger for an alms. These mothers, instead of being able to work for their honest livelihood, are forced to employ all their time in strolling to beg sustenance for their helpless infants: who as they grow up either turn thieves for want of work, or leave their dear native country to fight for the Pretender in Spain, or sell themselves to the Barbadoes.
Now let's update your SUMMARY.md
file, which functions as your table of contents.
# Summary
* [Introduction](README.md)
* [The Jabberwocky](chapter1.md)
* [A Modest Proposal](chapter2.md)
Gitbook allows you to test your book before you push it to the web by using this command:
$ gitbook serve
Looks nice, doesn't it? You can even make changes to the text, and your book will update on the fly.
Like what you see? Great. Let's move on!