Gitbook使用笔记
gitbook是github与markdown的结合体,我们可以通过markdown笔记记录书籍内容,然后发布到gitbook上,使用操作和流程与github类似,详细了解见官网以及Git
Gitbook安装及使用
1. 安装
|
|
2. 创建书籍
-
初始化一个
Gitbookcd到要创建书籍的目录下,比如~/books,然后运行1$ gitbook init终端会输出以下命令,并创建两个文件
1 2 3 4warn no summary file in this book info: create README.md info: create SUMMARY.md info: initialization is finished -
编写
README.md和SUMMARY.md这时文件夹下的目录为
1 2$ ls README.md SUMMARY.mdREADME.md是对创建书籍的介绍,这里面的内容会在整个gitbook的简介中出现SUMMARY.md是整个书籍的目录结构,这个文件的编写需要按照对应的格式,以标题的形式,每一个标题对应一个.md文件的路径,类似这样1 2 3 4 5 6 7 8 9 10 11 12 13# Summary * [Introduction](README.md) ----- * [Detection](detection/README.md) * [PointPillars](detection/pointpillars.md) * [Tracking](tracking/README.md) * [SC3D](tracking/sc3d.md) * [Segmentation](seg/README.md) * [SOLO](seg/solo.md) * [PointCloud](pointcloud/README.md) * [PV-CNN](pointcloud/pvcnn.md)我们可以按照自己对书籍的设想,编写对应的目录大纲
当做完更改之后,再次执行
git init,就会根据SUMMARY.md中编写的目录自动生成对应文件 -
编译
仍然在
~/books目录下,执行1 2 3 4 5 6 7 8 9 10 11 12 13$ gitbook build ---------------------------------------------------- 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 9 pages info: found 0 asset files info: >> generation finished with success in 0.5s !此时目录下会生成对应的书籍编译文件
_book1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27$ tree . -L 2 ------------------- . ├── _book │ ├── detection │ ├── gitbook │ ├── index.html │ ├── pointcloud │ ├── search_index.json │ ├── seg │ └── tracking ├── detection │ ├── pointpillars.md │ └── README.md ├── pointcloud │ ├── pvcnn.md │ └── README.md ├── README.md ├── seg │ ├── README.md │ └── solo.md ├── SUMMARY.md └── tracking ├── README.md └── sc3d.md 10 directories, 12 files编译得到的
_book目录就是对已有的书籍内容做了转换,变成了html网页文件,如果你想将gitbook链接到个人博客,只需要上传这个目录下的文件即可,具体操作见下文 -
本地运行
仍然在
~/books目录下,执行1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19$ gitbook serve # 这个命令会自动执行 gitbook build命令 --------------------------------- Live reload server started on port: 35729 Press CTRL+C to quit ... info: 7 plugins are installed info: loading plugin "livereload"... OK 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 9 pages info: found 0 asset files info: >> generation finished with success in 0.6s ! Starting server ... Serving book on http://localhost:4000这时打开浏览器,输入
http://localhost:4000,即可查看本地版的gitbook
OK,到这里关于gitbook的简单使用就介绍完了,下面记录下如何在个人主页上使用gitbook
将GitBook链接到个人博客
简单记录下
个人使用的是 hexo 框架以及 fluid 主题搭建的个人博客
使用gitbook的初衷就是,我想在个人博客上链接一个地址,这个网页记录一些比如力扣刷题笔记等自己学习的内容,所以就简单了解了一下gitbook
OK,那现在我默认已经拥有了自己的博客,并且已经按照上述流程初步体验了gitbook的使用,并且拥有了自己的第一个gitbook,如果你想把他链接到个人博客上,应该分以下三步:
-
将
gitbook原始内容上传至github远程仓库这里指的是自己编写的markdown笔记等
在
github新建一个仓库,这个仓库的名字会是你博客跳转到gitbook网页的后缀在
gitbook本地,初始化仓库,远程仓库设定为刚刚建立的仓库地址新建
.gitignore文件,里面的内容设置为1 2*~ _book上传当前文件到远程仓库的
main分支 -
编译
gitbook,将生成的_book中的内容上传到新的分支,叫做gh-pages1 2 3 4 5 6 7 8 9 10gitbook build mkdir book_build cp -r _book/* book_build cd book_build git init git remote add origin xxx git checkout -b gh-pages git add . git commit -m "first pub" git push origin gh-pages这样就将编译得到的
_book下面的静态网页文件上传到了远程仓库的gh-pages分支下登录
github,找到仓库->setting->options->Github pages,设置gh-pages为要展示的分支,保存,Over! -
设置个人博客中,对应的链接为
your-blog-address/xxx/,其中xxx既是远程仓库的名字,也是你的gitbook的名字
结果展示 leetcode· GitBook
