gitbook是可以将按照一定规范组织的Markdown文档转换成一个网页版电子书的工具,制作一些网站帮助文档等还是非常方便的,而且更新可以不依赖IT的开发同事,将编辑权限直接下放到产品经理等角色。
1、先安装node.js
下载地址:https://nodejs.org/en/download/ ,下载后直接双击安装即可
安装后,打开cmd控制台(win+r),输入如下命令可以查看版本:
2、安装gitbook
这里安装gitbook-cli ,就是gitbook的命令行版本,命令行安装即可: npm install gitbook-cli -g
3、创建电子书目录
有两个文件比较重要:
(1)book.json
"readme": "introduction.md" ,可以修改初始页展示哪个页面,默认是读取READEME.md的;
plugins 用于添加插件,好像需要把插件放到项目目录下,否则会提示找不到,就是直接在项目中用以下命令安装即可:
npm install gitbook-plugin-flexible-alerts gitbook-plugin-advanced-emoji gitbook-plugin-mermaid-gb3 gitbook-plugin-back-to-top-button gitbook-plugin-splitter gitbook-plugin-search-plus gitbook-plugin-page-footer-ex gitbook-plugin-chart gitbook-plugin-graph gitbook-plugin-include-csv
{ "title": "知识中心", "description": "使用文档", "author": "xxx", "output.name": "site", "gitbook": ">=3.2.2", "language": "zh-hans", "root": ".", "structure": { "readme": "introduction.md" }, "plugins": [ "-lunr", "-highlight", "-livereload", "-sharing", "-search", "search-plus", "-simple-page-toc@^0.1.1", "-prism@^2.1.0", "-prism-themes@^0.0.2", "advanced-emoji@^0.2.2", "-anchors@^0.7.1", "-include-codeblock@^3.0.2", ], "pluginsConfig": { "theme-default": { "showLevel": true }, "prism": { "css": [ "prism-themes/themes/prism-base16-ateliersulphurpool.light.css" ] }, "include-codeblock": { "template": "ace", "unindent": true, "edit": false }, "sharing": { "weibo": false, "facebook": false, "twitter": false, "google": false, "instapaper": false, "vk": false }, "simple-page-toc": { "maxDepth": 3, "skipFirstH1": true }, "anchor-navigation-ex": { "isRewritePageTitle": false, "tocLevel1Icon": "fa fa-hand-o-right", "tocLevel2Icon": "fa fa-hand-o-right", "tocLevel3Icon": "fa fa-hand-o-right" }, "sectionx": { "tag": "b" }, "page-footer-ex": { "copyright": "© xx公司", "markdown": false, "update_label": "更新时间:", "update_format": "YYYY-MM-DD HH:mm:ss" }, "chart": { "type": "highcharts" }, "styles": { "website": "styles/website.css" }, "fontsettings": { "theme": "white", "family": "serif", "size": 1 } } }
(2)SUMMARY.md
必须要有,是定义左侧的导航栏的
4、电子书初始化
gitbook init 会报错
C:UsersfrankAppDataRoaming pm ode_modulesgitbook-cli ode_modules pm ode_modulesgraceful-fspolyfills.js:287 if (cb) cb.apply(this, arguments)
修改这个文件
C:UsersandaAppDataRoaming pm ode_modulesgitbook-cli ode_modules pm ode_modulesgraceful-fspolyfills.js
注意不是这个:
C:UsersandaAppDataRoaming pm ode_modulesgitbook-cli ode_modulesgraceful-fspolyfills.js
注释掉这几行62-64:
//fs.stat = statFix(fs.stat)
//fs.fstat = statFix(fs.fstat)
//fs.lstat = statFix(fs.lstat)
5、启动服务
gitbook serve
然后在浏览器访问 http://localhost:4000 ,就可以查看了。
参考网页:
好用的插件可以参考:https://www.jianshu.com/p/427b8bb066e6
解决报错:https://lgl88911.gitee.io/2020/11/08/Windows%E4%B8%8BGitbook%E5%AE%89%E8%A3%85/