使用 Gitbook 来做笔记

装包:

  1. npm install gitbook-cli -g

创建笔记文件夹note并进入

  1. mkdir note && cd note

初始化gitbook

  1. gitbook init

这样,会生成2个文件

  • README.md 封面
  • SUMMARY.md 目录

启动项目:

  1. gitbook serve

这样,可以启动一个服务器,然后到 localhost:4000 端口,就可以看到这本书了。

在浏览器打开:

  1. localhost:4000

调整结构:

在note新建content文件夹将README.md,SUMMARY.md文件放在里面

  1. note -> content -> README.md,SUMMARY.md

创建 git 文件夹,然后里面就可以写笔记了。其实 gitbook 本身的使用技巧基本就是这些了。

  1. note -> content -> git

托管gitbook

在github上创建node仓库

然后,把项目变成一个nodejs的项目:

  1. npm init -y

然后,在package.json 中添加这些代码:

  1. "scripts": {
  2. "start": "gitbook serve ./content ./gh-pages",
  3. "build": "gitbook build ./content ./gh-pages",
  4. "deploy": "node ./scripts/deploy-gh-pages.js",
  5. "publish": "npm run build && npm run deploy",
  6. "port": "lsof -i :35729"
  7. },

运行本地gitbook

  1. npm start

删除_book文件夹

  1. rm -r _book

在note文件夹里创建一个.gitignore文件将不上传的文件添加

  1. # dependencies
  2. /node_modules
  3. /scripts
  4. /gh-pages

github备份(上传)操作

  1. git init
  2. git add -A
  3. git commit -a -m 'new'
  4. git remote add origin https://github.com/l552177239/note.git
  5. git push -u origin master

部署书籍到 gh-pages

这一步,可以手动做:

  • 第一步:运行:npm run build,把md文件转化为html放到gh-pages文件夹
  • 第二步:拷贝gh-pages中的所有文件,到gh-pages分支,然后上传
  • 第三步:以后每次修改完都拷贝到gh-pages分支,很麻烦所以,我们采用一个 npm 包,来帮助我们完成上面的操作

装包

  1. npm i gh-pages --save

然后创建配置文件note/scripts/deploy-gh-pages.js

将下面代码拷贝进去

  1. 'use strict';
  2. var ghpages = require('gh-pages');
  3. main();
  4. function main() {
  5. ghpages.publish('./dist', console.error.bind(console));
  6. }

这样,每次书稿有了修改,运行

  1. npm run publish

就可以把书稿部署到 http://l552177239.github.io/note

编辑书籍

可以修改 SUMMARY.md 来添加书籍目录

  1. # Summary
  2. * [Introduction](README.md)
  3. //README.md封面内容
  4. * 第一章
  5. - [第一小节:学习 Github](./git/1-github.md)
  6. //[目录上的名称](展示文章的地址)
  7. - [第二小节:学习 Gitbook](./git/2-gitbook.md)
  8. - [第三小节:Github 基本操作](./git/3-github.md)

文章内用markdown语法书写,具体怎么写请看下一章