gitBook應用

安裝

npm install gitbook -g

使用gitbook init初始化書籍目錄

README.md和Summary.md是兩個必須文件,README.md是對書籍的簡單介紹

gitbook init
Installing GitBook 3.2.3........

tree  /home/pi/mygithub/mynote/
/home/pi/mygithub/mynote/
├── README.md
└── SUMMARY.md

gitbook服務

使用gitbook serve編譯書籍

gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...
........
........
Starting server ...
Serving book on http://localhost:4000

建立書籍

gitbook build
git checkout --orphan gh-pages
git rm --cached -r .
rm -f *.md
echo "*~" > .gitignore
echo "_book" >> .gitignore

git commit -m "Ignore some files"
git checkout --orphan gh-pages
cp -r _book/* .
git add .
git commit -m "Publish book"
git config --global user.email "kawsing@gmail.com"
git config --global user.name "kawsing"
git remote add origin https://github.com/kawsing/mynote.git
git push -u origin gh-pages

變更內容

nano SUMMARY.md

# MYSUMMARY

* [Chapter1](chapter1/README.md)
  * [Section1.1](chapter1/section1.1.md)
  * [Section1.2](chapter1/section1.2.md)
* [Chapter2](chapter2/README.md)

gitbook build重新建立書籍

gitbook build
cp -r _book/* .
git add .
git commit -m "Publish Book"
git push -u origin gh-pages

完整流程

mkdir Book
cd Book/
gitbook init
gitbook build
pi@ubuntu:~/mygithub/Book$ ls
_book  README.md  SUMMARY.md

pi@ubuntu:~/mygithub/Book$ git checkout --orphan gh-pages
fatal: not a git repository (or any of the parent directories): .git

pi@ubuntu:~/mygithub/Book$ ls -a
.  ..  _book  README.md  SUMMARY.md

pi@ubuntu:~/mygithub/Book$ git init
Initialized empty Git repository in /home/pi/mygithub/Book/.git/

pi@ubuntu:~/mygithub/Book$ git checkout --orphan gh-pages
Switched to a new branch 'gh-pages'
git rm --cached -r .

rm -rf *~

echo "*~" > .gitignore
echo "_book" >> .gitignore
git checkout --orphan gh-pages

git init
git commit -m "Ignore some files"
cp -r _book/* .

git add .

git commit -m "Publish book"
git push -u origin gh-pages
git remote add origin https://github.com/kawsing/Book.git
git commit -m "Publish book"
git push -u origin gh-pages

pi@ubuntu:~/mygithub/Book$ ls
_book  gitbook  index.html  README.md  search_index.json  SUMMARY.md

Last updated