GitBook项目中用插件的方式安装github上的第三方模板

Tags: gitbook 

目录

说明

Gitbook的默认模板是theme-default,可以把它fork一份,然后自由修改,并且可以直接引用github上repo作为插件。

准备一个新的theme

theme-defaultfork为theme-lijiaocn,可以在里面增加或删除一些字符,便于与theme-default区分开。

package.json中的名称一定要修改:

将:

"name": "gitbook-plugin-theme-default",
"description": "Default theme for GitBook",

修改为:

"name": "gitbook-plugin-theme-lijiaocn",
"description": "Default theme for GitBook",

文件中的连接也修改:

1,$ s#https://github.com/GitbookIO/#https://github.com/lijiaocn/#

创建gitbook项目

先安装gitbook-cli

npm install gitbook-cli -g

gitbook命令默认位于/usr/local/bin中,需要将这个目录添加到环境变量PATH中:

export PATH="/usr/local/bin/":$PATH

创建一个gitbook项目:

mkdir custom-theme-example
cd custom-theme-example
gitbook init

如果遇到dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib的问题,可以用下面方法解决:

问题现象:
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
  Referenced from: /usr/local/bin//node
  Reason: image not found
[1]    55441 abort      gitbook init

解决方法:
brew update node
brew cleanup

设置项目的book.json

在gitbook目录中创建项目的配置文件book.json

{
    "author": "[email protected]",
    "isbn": "",
    "language":"zh",
    "gitbook": ">=3.0.0",
    "plugins":""
}

采用How to use a custom theme hosted on Github?中的建议,将github上theme repo作为插件安装:

{
    "author": "[email protected]",
    "isbn": "",
    "language":"zh",
    "gitbook": ">=3.0.0",
    "plugins":[
        {
            "name": "theme-lijiaocn",
            "version": "git+https://github.com/lijiaocn/theme-lijiaocn.git"
        }
    ]
}

运行gitbook install安装:

$ gitbook install
info: installing 1 plugins using [email protected]
info:
info: installing plugin "theme-lijiaocn"
info: install plugin "theme-lijiaocn" (git+https://github.com/lijiaocn/theme-lijiaocn.git) from NPM with version git+https://github.com/lijiaocn/theme-lijiaocn.git
/Users/lijiao/Work-Finup/books/custom-theme-example
└── [email protected]  (git+https://github.com/lijiaocn/theme-lijiaocn.git#3be9e673448b4a8e13e6405cb061cf4e172f2377)

启动:

gitbook serve --port 4005 --lrport 35735

插件更新

theme-lijiaocn插件更新之后,在使用该插件的gitbook项目中直接重新安装一遍插件,就会应用最新的版本:

gitbook install 

安装sitemap插件

sitemap插件

{
    "plugins": ["sitemap"],
    "pluginsConfig": {
        "sitemap": {
            "hostname": "http://mybook.com/"
        }
    }
}

参考

  1. theme-default
  2. theme-lijiaocn
  3. 怎样在gitbook上写一本书?
  4. dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
  5. GitBook Toolchain Documentation
  6. GitBook Configuration
  7. How to use a custom theme hosted on Github?

推荐阅读

Copyright @2011-2019 All rights reserved. 转载请添加原文连接,合作请加微信lijiaocn或者发送邮件: [email protected],备注网站合作

友情链接:  系统软件  程序语言  运营经验  水库文集  网络课程  微信网文  发现知识星球