LoginSignup
6

More than 5 years have passed since last update.

MacOSでGitBookの環境をセットアップする

Posted at

MarkDownのドキュメントをGitで手軽に管理できるGitBookを導入する。

条件:
* Mac OS Sierra
* npmがインストールされている

インストール〜ブックの作成

gitbook-cliのインストール

$ npm install gitbook-cli -g
$ source ~/.bashrc 

gitbookの初期化

$ cd [対象ディレクトリ]
$ gitbook init

以下のファイルが自動で生成されるため、これらをベースにブックを編集する。

  • README.md
  • SUMMARY.md

HTMLを出力する

gitbookをビルドすると_bookというフォルダへHTMLが出力される。

$ gitbook build

以下のコマンドでビルド&ローカルサーバーを立ち上げて確認することも可能。

$ gitbook serve

Starting server ...
Serving book on http://localhost:4000

localhostのポート4000を開く。

Kobito.f4pE0u.png

PDFを出力する

PDFで出力をする場合は、Calibreというアプリケーションが必要。
https://calibre-ebook.com/

手っ取り早くcaskでインストールする。

$ brew cask install calibre

以下のコマンドを実行すると、book.pdfというファイル名でpdfが出力される。

$ gitbook pdf

info: 7 plugins are installed 
info: 6 explicitly listed 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 1 pages 
info: found 0 asset files 
info: >> generation finished with success in 5.7s ! 
info: >> 1 file(s) generated

プレビューでbook.pdfを開いた場合

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6