github自动化构建电子书
1.创建仓库book
2.用Linux命令行克隆book到本地
3.用ll查看文件夹内容,应该存在LICENSE和README.md两个文件,如果没有就手动添加
4.在book目录下执行npm i -g gitbook-cil,安装gitbook
5.安装成功后新建两个文件ch01.md和SUMMARY.md
ch01.md
#第一章
这是第一章
SUMMARY.md
- [简介](README.md)
- [第一章](ch01.md)
6.添加完成后运行命令gitbook build,命令结束后会在原目录下生成_book文件夹,文件夹内包含index.html等文件
~/spa/book(master*) » ll _book 总用量 60 -rw-rw-r--. 1 wangding wangding 8096 2月 27 20:51 ch01.html drwxrwxr-x. 9 wangding wangding 237 2月 27 20:51 gitbook -rw-rw-r--. 1 wangding wangding 7694 2月 27 20:51 index.html -rw-rw-r--. 1 wangding wangding 1066 2月 27 20:51 LICENSE -rw-rw-r--. 1 wangding wangding 847 2月 27 20:51 package.json -rw-rw-r--. 1 wangding wangding 2345 2月 27 20:51 search_index.json
7.进入_book目录后运行lrd命令,在浏览器内输入External后面的地址即可访问到本地生成的电子书(其他文章会写如何安装lrd)
~/spa/book/_book(master*) » lrd
[Browsersync] Access URLs: --------------------------------------- Local: http://localhost:8080 External: http://192.168.56.144:8080 --------------------------------------- UI: http://localhost:3001 UI External: http://localhost:3001
到此为止只是在本地电脑上生成电子书
8.接下来回到Linux命令行执行rm -rf _book删除gitbook build生成的文件
9.回到book目录下将所有的文件推送到远程仓库上
以次执行命令:
~/spa/book(master) » gaa wangding@OFFICE ------------------------------------------------------------ ~/spa/book(master) » gcmsg "ok" wangding@OFFICE # 位于分支 master 无文件要提交,干净的工作区 ------------------------------------------------------------ ~/spa/book(master) » gp wangding@OFFICE Username for 'https://github.com': zhangjiacheng1997 Password for 'https://zhangjiacheng1997@github.com':
执行结束后回到GitHubbook仓库会发现有新添加文件,说明推送成功
10.推送结束后再用gitbook build生成_book文件
11.执行 mv _book ~/tmp将_book文件夹移动到根目录的tmp文件夹内
12.创建新分支gh-pages,执行下面命令后会自动切换到新分支
gco -b gh-pages
13.执行rm *删除新分支的所有文件
14.执行mv ~/tmp/_book/* .将之前移动到tmp下的_book内的文件复制到新分支上
~/spa/book(master*) » gaa ------------------------------------------------------------ ~/spa/book(master*) » gcmsg "ok" [gh-pages 5441136] book v0.1 publish 30 files changed, 3023 insertions(+), 13 deletions(-) delete mode 100644 README.md delete mode 100644 SUMMARY.md create mode 100644 ch01.html delete mode 100644 ch01.md create mode 100644 ch02.html delete mode 100644 ch02.md create mode 100644 gitbook/fonts/fontawesome/FontAwesome.otf create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.eot create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.svg create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.ttf create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.woff create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.woff2 create mode 100644 gitbook/gitbook-plugin-fontsettings/fontsettings.js create mode 100644 gitbook/gitbook-plugin-fontsettings/website.css create mode 100644 gitbook/gitbook-plugin-highlight/ebook.css create mode 100644 gitbook/gitbook-plugin-highlight/website.css create mode 100644 gitbook/gitbook-plugin-lunr/lunr.min.js create mode 100644 gitbook/gitbook-plugin-lunr/search-lunr.js create mode 100644 gitbook/gitbook-plugin-search/lunr.min.js create mode 100644 gitbook/gitbook-plugin-search/search-engine.js create mode 100644 gitbook/gitbook-plugin-search/search.css create mode 100644 gitbook/gitbook-plugin-search/search.js create mode 100644 gitbook/gitbook-plugin-sharing/buttons.js create mode 100644 gitbook/gitbook.js create mode 100644 gitbook/images/apple-touch-icon-precomposed-152.png create mode 100644 gitbook/images/favicon.ico create mode 100644 gitbook/style.css create mode 100644 gitbook/theme.js create mode 100644 index.html create mode 100644 search_index.json ------------------------------------------------------------ ~/spa/book(master*) » git push --set-upstream origin gh-pages Counting objects: 37, done. Compressing objects: 100% (34/34), done. Writing objects: 100% (36/36), 625.63 KiB | 0 bytes/s, done. Total 36 (delta 3), reused 0 (delta 0) remote: Resolving deltas: 100% (3/3), done. remote: remote: Create a pull request for 'gh-pages' on GitHub by visiting: remote: https://github.com/haungpeng/Ebook/pull/new/gh-pages remote: To http://github.com/haungpeng/Ebook * [new branch] gh-pages -> gh-pages 分支 gh-pages 设置为跟踪来自 origin 的远程分支 gh-pages。 ------------------------------------------------------------ ~/spa/book(master*) » git checkout gh-pages 切换到分支 'gh-pages' ------------------------------------------------------------ ~/spa/book(master*) » ll 总用量 32 drwxrwxr-x. 3 wangding wangding 148 2月 27 16:14 _book -rw-rw-r--. 1 wangding wangding 7307 2月 27 16:17 ch01.html -rw-rw-r--. 1 wangding wangding 6995 2月 27 16:17 ch02.html drwxrwxr-x. 9 wangding wangding 237 2月 27 16:17 gitbook -rw-rw-r--. 1 wangding wangding 6927 2月 27 16:17 index.html -rw-rw-r--. 1 wangding wangding 1063 2月 27 15:32 LICENSE -rw-rw-r--. 1 wangding wangding 1412 2月 27 16:17 search_index.json ------------------------------------------------------------ ~/spa/book(master*) » git checkout master 切换到分支 'master'
15.到此为止已经把电子书发布到git上了,登录https://travis-ci.org/关联到自己的github
16.接下来参考https://segmentfault.com/a/1190000015274243的步骤
17.添加的两个文件.travis.yml和package.json
language: node_js node_js: - "node" after_script: - gitbook build - cd ./_book - git init - git config user.name "${USER_NAME}" - git config user.email "${USER_EMAIL}" - cp ../CNAME . - git add . - git commit -m "publish gitbook" - git push --force --quiet "https://${ACC_TOKEN}@${GH_REF}" master:${BRANCH} branches: only: - master
{ "name": "spa", "version": "1.0.0", "description": "SPA 富应用开发课程资料。", "scripts": { "test": "echo \"nothing to test!\" && exit 0" }, "repository": { "type": "git", "url": "git+https://github.com/wangding/spa.git" }, "author": "wangding", "license": "MIT", "bugs": { "url": "https://github.com/wangding/spa/issues" }, "homepage": "https://github.com/wangding/spa#readme", "devDependencies": { "gitbook-cli": "^2.3.2" } }
里面内容根据自己实际情况更改