gitbook

步骤1

安装node.js 最新版 和 git

步骤2

npm install -g gitbook-cli (可以使用淘宝镜像)

安装在C:\AppData\Roaming\miniconfig

步骤3

新建了一个叫 mybook 的文件夹,在 mybook 文件夹下执行以下命令:

gitbook init

初始化文件在C:\Users\Administrator\.gitbook\versions\3.2.3下.

在 mybook 文件夹中,编辑 SUMMARY.md 文件,内容修改为:

# 目录
* [前言](README.md)
* [第一章](Chapter1/README.md)
 * [第1节:衣](Chapter1/衣.md)
 * [第2节:食](Chapter1/食.md)
 * [第3节:住](Chapter1/住.md)
 * [第4节:行](Chapter1/行.md)
* [第二章](Chapter2/README.md)
* [第三章](Chapter3/README.md)
* [第四章](Chapter4/README.md)

在 mybook 文件夹中再次执行 gitbook init 命令。GitBook 会查找 SUMMARY.md 文件中描述的目录和文件,如果没有则会将其创建。

步骤4

执行

接着我们执行 gitbook serve 来预览这本书籍,执行命令后会对 Markdown 格式的文档进行转换,默认转换为 html 格式,最后提示 “Serving book on http://localhost:4000”。打开浏览器.

构建书籍

当你写得差不多,你可以执行 gitbook build 命令构建书籍,默认将生成的静态网站输出到 _book 目录。实际上,这一步也包含在 gitbook serve 里面,因为它们是 HTML,所以 GitBook 通过 Node.js 给你提供服务了。
  当然了,build 命令可以指定路径:

注: 生成的 html, 不能够直接访问跳转,因为存在 json 数据请求。可以通过编译器读取,或者搭建本地服务器访问

$ gitbook build [书籍路径] [输出路径]
1
  serve 命令也可以指定端口:

$ gitbook serve --port 2333
1
  你还可以生成 PDF 格式的电子书:

$ gitbook pdf ./ ./mybook.pdf
1
  生成 epub 格式的电子书:

$ gitbook epub ./ ./mybook.epub
1
  生成 mobi 格式的电子书:

$ gitbook mobi ./ ./mybook.mobi
1
  如果生成不了,你可能还需要安装一些工具,比如 ebook-convert。或者在 Typora 中安装 Pandoc 进行导出。

下载地址 :https://calibre-ebook.com/download_windows

安装好要配置环境变量

构建书籍,才能点目录gitbook build

步骤五

在 mybook 文件夹下,右击用git bash here执行以下命令

git config --global user.name "用户名"

git config --global user.email 邮箱

git init

git add .

git commit -m 'gitbook测试' #gitbook测试描述该项目

git remote add origin 仓库的地址

git push -u origin master
1.如果出现以下错误提示

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to '仓库地址'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

可以通过以下命令解决该问题。
git pull --rebase origin master
执行语句 git push -u origin master 即可完成代码上传到gitee或者github

2.如果出现以下错误:

remote: Incorrect username or password ( access token )
fatal: Authentication failed for '仓库地址'

有可能是git config --global user.name "用户名"这个命令的用户名错误,用户名即是空间地址(以gitee为例:https://gitee.com/ 后面的名字)。也有可能是你的当时弹出框让你设置用户名和密码的错误,解决方法:在控制面板下的用户帐户下的凭据管理器下的普通凭据修改git:https://gitee.com/(以gitee为例)

执行语句 git push -u origin master 即可完成代码上传到gitee或者github

第二次上传:

git add .

git commit -m 'gitbook测试' #gitbook测试描述该项目,可以修改

git push -u origin master

步骤六

在你的项目下的 服务 中的 Gitee pages 打开 完成配置即可

分支:master

目录:_book

就会返回给你一个站点,使用站点浏览即可.

步骤七

【Gitbook】实用配置及插件介绍

在根目录(即与SUMMARY.md同级的目录)下的配置文件 book.json(如果没有则新建)中添加插件配置,代码如下:

{
	"title" : "Django课件",
	"author" : "作者",
	"description" : "Django课件",
	"language" : "zh-hans",
	"links" : {
	    "sidebar" : {
	        "关于作者" : "http://www.zqedu.cn/single/About-Me"
	    }
	},
	"plugins" : [
	"toggle-chapters",
	"sectionx",
	"tbfed-pagefooter",
	"include-codeblock",
	"splitter",
	"mermaid",
	"codeblock-filename",
	"prism",
    "-highlight",
     "simple-page-toc",
     "navigator"
	],
	"pluginsConfig": {
	    "tbfed-pagefooter": {
	        "copyright":"Copyright © zqedu.cn 2018",
	        "modify_label": "该文件修订时间:",
	        "modify_format": "YYYY-MM-DD HH:mm:ss"
	    },
	    "sharing": {
	        "weibo": true,
	        "facebook": true,
	        "twitter": true,
	        "google": false,
	        "instapaper": false,
	        "vk": false,
	        "all": [
	            "facebook", "google", "twitter",
	                "weibo", "instapaper"
	        ]
	    },
	    "simple-page-toc": {
            "maxDepth": 3,
            "skipFirstH1": true
       }
	}
}

代码解释

{
	"title" : "Django课件",
	"author" : "作者",
	"description" : "Django课件",
	"language" : "zh-hans",
	"links" : {
	    "sidebar" : {
	        "关于作者" : "http://www.zqedu.cn/single/About-Me"
	    }
	},
	"plugins" : [
	"toggle-chapters", // 是左侧的章节目录可以折叠 
	"sectionx",      // 将页面分块显示 
	"tbfed-pagefooter",  // 为页面添加页脚 
	"include-codeblock",  // 使用代码块的格式显示所包含文件的内容. 该文件必须存在. 
	"splitter",  // 侧边栏的宽度可以自由调节 
	"mermaid",  // 支持渲染Mermaid图表 
	"codeblock-filename" // 为代码块添加文件名称 
 
	],
	"pluginsConfig": {
	    "tbfed-pagefooter": { // 每个文章的页脚配置
	        "copyright":"Copyright © zqedu.cn 2018",
	        "modify_label": "该文件修订时间:",
	        "modify_format": "YYYY-MM-DD HH:mm:ss"
	    },
	    "sharing": {  //分享配置
	        "weibo": true,
	        "facebook": true,
	        "twitter": true,
	        "google": false,
	        "instapaper": false,
	        "vk": false,
	        "all": [
	            "facebook", "google", "twitter",
	                "weibo", "instapaper"
	        ]
	    }
	}
}

执行

gitbook install

gitbook serve

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值