安装gitbook命令

前提:已经安装nodejs

npm install -g gitbook-cli

查看版本号

gitbook -V

gitbook命令

gitbook -h

 Usage: gitbook [options] [command]

 Commands:

   ls                        List versions installed locally
   current                   Display currently activated version
   ls-remote                 List remote versions available for install
   fetch [version]           Download and install a <version>
   alias [folder] [version]  Set an alias named <version> pointing to <folder>
   uninstall [version]       Uninstall a version
   update [tag]              Update to the latest version of GitBook
   help                      List commands for GitBook
   *                         run a command with a specific gitbook version

 Options:

   -h, --help               output usage information
   -v, --gitbook [version]  specify GitBook version to use
   -d, --debug              enable verbose error
   -V, --version            Display running versions of gitbook and gitbook-cli

gitbook help

build [book] [output]       编译指定目录,输出Web格式,输出一个静态网站到目录[output]
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
        --format            Format to build to (Default is website; Values are website, json, ebook)
        --[no-]timing       Print timing debug information (Default is false)

serve [book] [output]       启动本地server预览localhost:4000
        --port              Port for server to listen on (Default is 4000)
        --lrport            Port for livereload server to listen on (Default is 35729)
        --[no-]watch        Enable file watcher and live reloading (Default is true)
        --[no-]live         Enable live reloading (Default is true)
        --[no-]open         Enable opening book in browser (Default is false)
        --browser           Specify browser for opening book (Default is )
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
        --format            Format to build to (Default is website; Values are website, json, ebook)

install [book]              install all plugins dependencies
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

parse [book]                parse and print debug information about a book
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

init [book]                 setup and create files for chapters 初始化一个新的gitbook目录
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

pdf [book] [output]         build a book into an ebook file 编译为PDF格式并输出
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

epub [book] [output]        build a book into an ebook file 编译为epub格式并输出
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

mobi [book] [output]        build a book into an ebook file 编译为mobi格式并输出
        --log               Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

开始写

从gitbook直接克隆到本地开始写

会自动生成chapter1.md,可以删除也可以直接修改名称,编辑完后直接提交

在本地已编辑好书后,提交到远程gitbook仓库

  1. 拿到提交的地址,如果为新书,则先新建gitbook然后拿到地址
  2. git init该目录
  3. 添加远程地址
git remote add gitbook https://push.gitbook.io/username/book-name.git

注:如果是用第三方登录,如github, twitter等,要先到账户设置中设置用户名和密码用于验证。

发布

git add
git commit
git push

安装插件

更换主题

npm上面搜索gitbook-theme。安装主题和安装插件一样安装。

  1. 通过npm搜索出来的结果提示安装npm install gitbook-theme-maxiang
  2. 根目录新建一个文件book.json,选项参见
{
    "plugins": ["thePlugin"]
}
  1. 运行gitbook install安装json文件中的所有插件
  2. gitbook serve预览
    可以删除npm下载下来的主题文件夹,_book保留提交,会生成的新的样式文件。

更换封面

错误集锦

1 在启动gitbook serve时,报错:

TypeError: Path must be a string. Received undefined

不是真的路径有错误,而是该文件里面的内容有无法识别,转换为html格式文件。文件里面的HTML标签一定要放在代码块里面。

2 read时只显示其中一部分的内容
可能在写中间某个文件时,里面有无法生成html格式的内容,导致之后的文件都没有编译成功。

版权声明:本文为for-you原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/for-you/p/12761684.html