DEV Community

Sh Raj
Sh Raj

Posted on β€’ Originally published at t.me

5 2 1 1 1

Building and Serving a GitBook Documentation

Building and Serving a GitBook Documentation

GitBook is a powerful tool for creating beautiful documentation and books using Markdown. This article provides a step-by-step guide on how to build, serve, and deploy your GitBook documentation.

Step 1: Install GitBook CLI

First, ensure you have Node.js installed on your machine. Then, install GitBook CLI globally using npm:

npm install -g gitbook-cli
Enter fullscreen mode Exit fullscreen mode

Step 2: Initialize Your GitBook

Navigate to the directory where you want to create your documentation and initialize a new GitBook project:

gitbook init
Enter fullscreen mode Exit fullscreen mode

This command will generate the initial structure for your GitBook, including the README.md and SUMMARY.md files.

Step 3: Serve Your GitBook Locally

To preview your GitBook, you can serve it locally. Run the following command in your project directory:

gitbook serve
Enter fullscreen mode Exit fullscreen mode

This command will build the book and start a local server. You can view your documentation by opening your web browser and navigating to http://localhost:4000.

Step 4: Build Your GitBook

Once you are satisfied with your documentation, you can build it for deployment. Run the following command to generate the static site files:

gitbook build
Enter fullscreen mode Exit fullscreen mode

This will create a _book directory containing all the HTML, CSS, and JavaScript files needed for your documentation.

Step 5: Deploy Your GitBook

There are multiple ways to deploy your GitBook. One common method is to use GitHub Pages.

Using GitHub Pages:

  1. Create a GitHub Repository:
    Create a new repository on GitHub for your documentation.

  2. Push Your GitBook to GitHub:
    Initialize a git repository in your GitBook project directory, commit your files, and push them to GitHub.

   git init
   git add .
   git commit -m "Initial commit"
   git remote add origin <your-repo-url>
   git push -u origin master
Enter fullscreen mode Exit fullscreen mode
  1. Deploy to GitHub Pages: Switch to the gh-pages branch and copy the contents of the _book directory.
   git checkout --orphan gh-pages
   git rm -rf .
   cp -r _book/* .
   git add .
   git commit -m "Deploy GitBook"
   git push -u origin gh-pages
Enter fullscreen mode Exit fullscreen mode

Your documentation should now be available at https://<username>.github.io/<repository>.

Using Netlify:

  1. Create a Netlify Account:
    Sign up for a free account on Netlify.

  2. Connect Your GitHub Repository:
    In the Netlify dashboard, click on "New site from Git" and connect your GitHub repository.

  3. Configure Build Settings:
    Set the build command to gitbook build and the publish directory to _book.

  4. Deploy Your Site:
    Click "Deploy site" to start the deployment process. Your documentation will be live on a Netlify URL.

Conclusion

By following these steps, you can easily build, serve, and deploy your GitBook documentation. Whether using GitHub Pages, Netlify, or another hosting service, GitBook provides a straightforward way to create professional and accessible documentation.

https://t.me/sopbots/48

πŸ‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay