gitbook的安装与使用


 

 GitBook 是一个基于 Node.js 的命令行工具,可使用 Github/Git 和 Markdown 来制作精美的电子书。

一、官网下载nodejs直接安装 

传送门,安装完成后如下:

可以看到npm也安装了,此时可以在cmd控制台进行验证(win+r),输入cmd进入控制台:

C:\pc>node -v
v8.11.1 C:\pc>npm -v 5.6.0

C:\pc>yarn -v
1.22.10

二、安装gitbook

在cmd控制台输入如下命令进行安装 一下两种方式选其一:

--1、安装了yarn 安装gitbook 方式如下:
C:\Users\JourneyOfFlower>yarn global add gitbook-cli
 
--2、安装了npm 安装gitbook 方式如下:
C:\Users\wwwli>npm install gitbook-cli -g
C:\Users\wwwli\AppData\Roaming\npm\gitbook -> C:\Users\wwwli\AppData\Roaming\npm\node_modules\gitbook-cli\bin\gitbook.js+ gitbook-cli@2.3.2
added 578 packages from 672 contributors in 251.912s

 查看安装的版本:

C:\Users\wwwli>gitbook -V
CLI version: 2.3.2
GitBook version: 3.2.3

 可能会出现如下报错:

 解决方案:

找到上述路径的 polyfills.js 文件,打开它,屏蔽掉使用 cb.apply 的代码及相关函数

 找到 statFix 函数的使用位置,屏蔽掉后 保存。

 

再运行使用gitbook没有任何问题

gitbook出现TypeError: cb.apply is not a function解决办法 - 暴力正

Gitbook错误"cb.apply is not a function"的解决办法 | Mizeri

三、安装gitbook editor windows版

官网地址:gitbook editor for windows

 备用下载链接:https://pan.baidu.com/s/1nX6FRtyzvdNXj8ijaVIfng  提取码:3b7w

        https://journeyofflower.lanzoui.com/i9YkIrxqeza  密码:76xw

直接运行.exe文件,如图:

此时可点击Do This Later进入

 

 点击进入编辑即可:

之后保存即可

 

四、测试

cmd控制台进入所建的电子书目录下:

进行初始化

输入:gitbook init filename 

e:\Gitbook\2019\Import\test>gitbook init Installing GitBook 3.2.3 gitbook@3.2.3 C:\Users\FUJIAN~2\AppData\Local\Temp\tmp-186002ka7aHl7tyHD\node_modules\gitbook ├── escape-html@1.0.3 ├── destroy@1.0.4 ├── escape-string-regexp@1.0.5 ├── ignore@3.1.2 ├── bash-color@0.0.4 ├── gitbook-plugin-livereload@0.0.1 ├── cp@0.2.0 ├── github-slugid@1.0.1 ├── graceful-fs@4.1.4 ├── nunjucks-do@1.0.0 ├── q@1.4.1 ├── spawn-cmd@0.0.2 ├── gitbook-plugin-fontsettings@2.0.0 ├── open@0.0.5 ├── is@3.3.0 ├── direction@0.1.5 ├── object-path@0.9.2 ├── extend@3.0.2 ├── gitbook-plugin-search@2.2.1 ├── json-schema-defaults@0.1.1 ├── jsonschema@1.1.0 ├── crc@3.4.0 ├── urijs@1.18.0 ├── semver@5.1.0 ├── front-matter@2.3.0 ├── immutable@3.8.2 ├── dom-serializer@0.1.0 (domelementtype@1.1.3, entities@1.1.2) ├── error@7.0.2 (string-template@0.2.1, xtend@4.0.1) ├── tmp@0.0.28 (os-tmpdir@1.0.2) ├── npmi@2.0.1 (semver@4.3.6) ├── omit-keys@0.1.0 (array-difference@0.0.1, isobject@0.2.0) ├── send@0.13.2 (fresh@0.3.0, etag@1.7.0, statuses@1.2.1, range-parser@1.0.3, ms@0.7.1, depd@1.1.2, debug@2.2.0, mime@1.3.4, http-errors@1.3.1, on-finished@2.3.0) ├── mkdirp@0.5.1 (minimist@0.0.8) ├── resolve@1.1.7 ├── rmdir@1.2.0 (node.flow@1.2.3) ├── fresh-require@1.0.3 (is-require@0.0.1, shallow-copy@0.0.1, sleuth@0.1.1, astw@1.3.0, through2@0.6.5, acorn@0.9.0, escodegen@1.11.0) ├── js-yaml@3.12.1 (esprima@4.0.1, argparse@1.0.10) ├── gitbook-plugin-theme-default@1.0.7 ├── cpr@1.1.1 (rimraf@2.4.5) ├── tiny-lr@0.2.1 (parseurl@1.3.2, livereload-js@2.4.0, qs@5.1.0, debug@2.2.0, body-parser@1.14.2, faye-websocket@0.10.0) ├── read-installed@4.0.3 (debuglog@1.0.1, util-extend@1.0.3, slide@1.1.6, readdir-scoped-modules@1.0.2, read-package-json@2.0.13) ├── gitbook-plugin-lunr@1.2.0 (html-entities@1.2.0, lunr@0.5.12) ├── chokidar@1.5.0 (path-is-absolute@1.0.1, async-each@1.0.1, inherits@2.0.3, glob-parent@2.0.0, is-glob@2.0.1, is-binary-path@1.0.1, anymatch@1.3.2, readdirp@2.2.1) ├── nunjucks@2.5.2 (asap@2.0.6, yargs@3.32.0, chokidar@1.7.0) ├── gitbook-plugin-highlight@2.0.2 (highlight.js@9.2.0) ├── moment@2.13.0 ├── gitbook-plugin-sharing@1.0.2 (lodash@3.10.1) ├── gitbook-markdown@1.3.2 (kramed-text-renderer@0.2.1, gitbook-html@1.3.3, kramed@0.5.6, lodash@4.17.11) ├── i18n-t@1.0.1 (lodash@4.17.11) ├── cheerio@0.20.0 (entities@1.1.2, css-select@1.2.0, htmlparser2@3.8.3, jsdom@7.2.2, lodash@4.17.11) ├── juice@2.0.0 (slick@1.12.2, deep-extend@0.4.2, batch@0.5.3, cssom@0.3.1, commander@2.9.0, cross-spawn-async@2.2.5, web-resource-inliner@2.0.0) ├── gitbook-asciidoc@1.2.2 (gitbook-html@1.3.3, asciidoctor.js@1.5.5-1, lodash@4.17.11) ├── request@2.72.0 (tunnel-agent@0.4.3, aws-sign2@0.6.0, forever-agent@0.6.1, oauth-sign@0.8.2, is-typedarray@1.0.0, caseless@0.11.0, stringstream@0.0.6, aws4@1.8.0, isstream@0.1.2, json-stringify-safe@5.0.1, tough-cookie@2.2.2, qs@6.1.2, node-uuid@1.4.8, combined-stream@1.0.7, mime-types@2.1.21, bl@1.1.2, hawk@3.1.3, http-signature@1.1.1, har-validator@2.0.6, form-data@1.0.1) └── npm@3.9.2 info: create SUMMARY.md info: initialization is finished

 此时并不是一帆风顺的,依然会出现错误

 

 后面参考了 gitbook从入门到放弃_简明AI工作室 

发现是Nodejs版本过高,需要降低Nodejs的版本到 v12.22.1

于是查看自己电脑的Nodejs版本  确实很高

C:\Users\JourneyOfFlower>node -v
v16.4.2

方案一:

卸载Nodejs  Window下完全卸载删除Nodejs

安装Nodejs v12.22.1 https://nodejs.org/dist/

方案二:

Nodejs降低或切换使用的版本

再执行 gitbook init rycloud

 

启动查看服务

输入:gitbook serve filename

e:\Gitbook\2019\Import\test>gitbook serve Live reload server started on port: 35729 Press CTRL+C to quit ... info: 7 plugins are installed info: loading plugin "livereload"... OK info: loading plugin "highlight"... OK info: loading plugin "search"... OK info: loading plugin "lunr"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 3 pages info: found 1 asset files info: >> generation finished with success in 1.2s ! Starting server ... Serving book on http://localhost:4000

 解决方案

浏览器访问:http://localhost:4000

 之后就可以尽情的编辑了

 

五、问题

1、生成的静态文件无法跳转

解决方法:修改js文件,参照

  • 找到项目目录gitbook
  • 找到目录下的theme.js文件
  • if(m)改成if(false) 

参考链接: https://www.cnblogs.com/kingsonfu/p/10255123.html

原文链接:gitbook的安装与使用 - EggChilde - 博客园 (cnblogs.com)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM