Skip to content

Instantly share code, notes, and snippets.

@hdsenevi
Last active July 30, 2024 15:11
Show Gist options
  • Save hdsenevi/fceb19ea02ff0aaf5efb102425a0393b to your computer and use it in GitHub Desktop.
Save hdsenevi/fceb19ea02ff0aaf5efb102425a0393b to your computer and use it in GitHub Desktop.
Publishing Gitbook documentation on Github pages
  1. Create git repo
  2. Clone git repo
  3. Install gitbook-cli if not setup already npm install -g gitbook-cli
  4. gitbook help to verify
  5. Go inside repo folder
  6. gitbook init
  7. Verify by using gitbook serve
  8. Add .gitignore https://github.com/github/gitignore/blob/master/GitBook.gitignore
  9. Push all the above to master
  10. Create gh-pages branch
  11. Push to remote
  12. Checkout master
  13. npm init
  14. npm i gulp gulp-gh-pages gulp-load-plugins --save-dev
  15. Crete a gulpfile.js and add the following to it
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');

const $ = gulpLoadPlugins();

gulp.task('publish', () => {
  console.log('Publish Gitbook (_book) to Github Pages');
  return gulp.src('./_book/**/*')
    .pipe($.ghPages({
      origin: 'origin',
      branch: 'gh-pages'
    }));
});
  1. Run gulp publish or add the following to script section in package.json
"serve": "gitbook serve",
"publish": "node_modules/.bin/gulp publish"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment