nodejs和gitbook制作电子书

gitBook官网: https://www.gitbook.com/

win10安装node.js

node.js官网:http://nodejs.cn/download/

1、下载安装node.js,默认也把npm勾选安装了,选择安装路径,例如:D:\Program Files\nodejs\。npm -version命令检查npm安装是否成功

2、配置环境变量

Ubuntu18.04安装node.js

sudo apt install nodejs # 使用 apt 安装 node
sudo apt install npm # 使用 apt 安装 npm

ubunu 18.04 无法安装npm

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

使用下面的命令安装

sudo apt install aptitude
sudo aptitude install npm

遇见这个选项:

     Keep the following packages at their current version:
1)     libssl-dev [Not Installed]                         
2)     node-gyp [Not Installed]                           
3)     nodejs-dev [Not Installed]                         
4)     npm [Not Installed]     

Accept this solution? [Y/n/q/?] ?

如果选y,没什么用,先选?再选n就安装成功了,我也不知道为什么(我的按Y就好了,上面是参考)

升级node

利用n来管理版本

sudo npm install -g n

n来下载node版本

sudo n lts 长期支持
sudo n stable 稳定版
sudo n latest 最新版
sudo n 8.4.0 直接指定版本下载

切换版本

sudo n
直接键盘上下移动选择你要的版本,回车确认

或者直接指定版本

sudo n 8.10.0

查看node版本

node -v 注意本终端下查看有可能没有变化,选择新建一个终端查看

升级npm

sudo npm i -g npm

安装gitbook

3、下载gitbook工具 , 全局安装gitbook。

npm install gitbook-cli -g 

4、由于安装过程默认使用国外镜像,可以考虑切换国内镜像。

npm config set registry=http://registry.npm.taobao.org

5、检查gitbook是否安装成功,如果在版本下面出现Installing GitBook xxx,说明此时gitbook还未安装成功,会自动安装gitbook

gitbook -V

gitbook测试

进入D:\workspace\gitbook\book_test

1、初始化book_test

2、启动book_test服务器,然后在浏览器地址栏中输入 http://localhost:4000 便可预览书籍。

gitbook serve

3、生成静态html文档

gitbook build

gitbook editor可视化编辑工具

下载地址:https://legacy.gitbook.com/editor

更改gitbook根目录

GitBook Editor--->Change Library Path

多级目录编辑

右击,添加文章

浏览器访问,生成静态html,与上面相同

Ubuntu18.04 安装Gitbook Editor

1、安装后点击无反应或

gitbook-editor: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory

sudo apt -y install libgconf2-4

Gtk-Message: 08:53:53.198: Failed to load module "canberra-gtk-module"

sudo apt-get install libcanberra-gtk-module 

启动命令:gitbook-editor

2、打开gitbook editor后,新建Book但是不能打开,提示没有git仓库被配置

  • 新建一个git仓库,git clone到本地
  • 把.git和.gitignore替换掉被自动创建的

gitbook build命令导出的html不能跳转?

解决方案一

gitbook build --gitbook=2.6.7 

如果遇到:

Error loading version latest: Error: Cannot find module 'internal/util/types'

 

将node版本降低:

// 1.安装node管理 n
sudo npm install -g n 
// 2. 降低版本,更新npm
sudo n 6

sudo npm install npm -g
// 3.此时运行gitbook2.6.7的命令即可。
gitbook build --gitbook=2.6.7
// 4. 待转换完成后,将npm版本(例如9.10.0)切回来即可,以免影响其他模块
sudo n 9.10.0

注意:windows上并不支持n模块

解决方案二(有闪烁)

  • 在导出的文件夹目录下找到gitbook->theme.js文件
  • 找到下面的代码(搜索 if(m)for(n.handler&&
if(false)for(n.handler&&(i=n,n=i.handler,o=i.selector),o&&de.find.matchesSelector(Ye,o),n.guid||(n.guid=de.guid++),(u=m.events)||(u=m.events={}),(a=m.handle)||(a=m.handle=function(t){return"undefined"!=typeof de&&de.event.triggered!==t.type?de.event.dispatch.apply(e,arguments):void 0}),t=(t||"").match(qe)||[""],l=t.length;l--;)s=Ze.exec(t[l])||[],h=g=s[1],d=(s[2]||"").split(".").sort(),h&&(f=de.event.special[h]||{},h=(o?f.delegateType:f.bindType)||h,f=de.event.special[h]||{},c=de.extend({type:h,origType:g,data:r,handler:n,guid:n.guid,selector:o,needsContext:o&&de.expr.match.needsContext.test(o),namespace:d.join(".")},i),(p=u[h])||(p=u[h]=[],p.delegateCount=0,f.setup&&f.setup.call(e,r,d,a)!==!1||e.addEventListener&&e.addEventListener(h,a)),f.add&&(f.add.call(e,c),c.handler.guid||(c.handler.guid=n.guid)),o?p.splice(p.delegateCount++,0,c):p.push(c),de.event.global[h]=!0)}
  • 将if(m)改成if(false)

参考地址:

Windows上使用gitbook制作电子书:https://blog.csdn.net/zl1zl2zl3/article/details/71123902
GitBook 使用教程:https://www.jianshu.com/p/421cc442f06c

ubuntu18.04下安装node:https://www.cnblogs.com/guanine/p/9392411.html
「wjfqvi」的原创文章 原文链接:https://blog.csdn.net/weixin_43880667/article/details/86515908

 

posted @ 2019-08-05 09:42  逐梦客!  阅读(1002)  评论(0)    收藏  举报