gitbook 入门

1. GitBook 介绍

GitBook 是基于 Node.js 命令行工具,支持 Markdown 语法,可以输出 PDF, HTML, eBook 格式的电子书,个人认为更适合技术写作。个人推荐使用 Typora + git + GitBook。

2. 安装 GitBook

  • 下载安装 Node.js 下载地址 , Node.js 会默认安装 npm (node 包管理模块) 模块。

    • 解压缩安装包
      1. xz -d node-v12.16.3-linux-x64.tar.xz
      2. tar -xvf node-v12.16.3-linux-x64.tar -C ~/software/
      3. export PATH=$PATH:~/software/node-v12.16.3-linux-x64/bin
      4. source ~/.bashrc
  • 安装 GitBook

    1. npm install -g gitbook-cli
  • 安装 gitbook 转换 pdf 插件 calibra

    ​ 1. sudo -v && wget --no-check-certificate -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin install_dir=/opt

  • 安装 Typora

    1. wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
    2. sudo add-apt-repository 'deb https://typora.io/linux ./'
    3. sudo apt-get update
    4. sudo apt-get install typora
  • 安装 Git

    1. sudo add-apt-repository ppa:git-core/ppa
    2. sudo apt update
    3. sudo apt install git

3. 使用 GitBook

  • 初始化,执行以下指令,会在当前目录下产生以下两个文件。

    gitbook init

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pyf54EzW-1588240716044)(E:\like_shadows\Document\gitbook\pictures\Snipaste_2020-04-29_20-58-58.png)]

README.md 	//关于书籍的介绍
SUMMARY.md  //书籍的目录结构  
  • 添加书籍目录,即编辑 SUMMARY.md文件

    # Summary
    
    * [Introduction](README.md)
    * [Chapter-1: Architecture](Chapter-1/README.md)
      * [Part A: Architecture](Chapter-1/Part A/README.md)
        * [1. Contents](Chapter-1/Part A/Contents.md)
        * [2. General description](Chapter-1/Part A/General description.md)
      * [Part B: Acronyms](Chapter-1/Part B/README.md)
      * [Part C: Core Specification](Chapter-1/Part C/README.md)
    * [Chapter-2: Controller](Chapter-2/README.md)
    * [Chapter-3: Host](Chapter-3/README.md)
    
  • 更新目录,执行如下指令,则会根据 SUMMARY.md的内容创建书籍的目录文件。

    gitbook init

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LUHmmiNV-1588240716046)(E:\like_shadows\Document\gitbook\pictures\Snipaste_2020-04-30_12-31-27.png)]

  • 生成 pdf 书籍,则会在目录下生成对应的 pdf 文件。

    gitbook pdf ./ mybook.pdf

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3Fka3Ai7-1588240716047)(E:\like_shadows\Document\gitbook\pictures\Snipaste_2020-04-30_13-10-18.png)]

  • 使用网页预览书籍

    1. gitbook serve

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QnveteBr-1588240716049)(E:\like_shadows\Document\gitbook\pictures\Snipaste_2020-04-30_17-21-03.png)]

2. 打开浏览器,输入 localhost:4000, 即可预览书籍, 结果如下

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mD0OwCcb-1588240716052)(E:\like_shadows\Document\gitbook\pictures\Snipaste_2020-04-30_17-23-38.png)]

3. 也可以指定端口号 gitbook serve --port 5000

4. 使用 Git 上传书籍

  • 初始化本地书籍仓库

    git init

  • 在服务器上 (github) 创建远程仓库,得到仓库的 URL

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z4fjNlpY-1588240716053)(E:\like_shadows\Document\gitbook\pictures\Snipaste_2020-04-30_17-53-21.png)]

  • 建立本地仓库与远程仓库的关联

    git remote add origin [url]

  • 然后就可以使用以下指令上传和下载

    git push

    git pull

至此,就可以欢快在任何地方使用 GitBook 了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值