gitbook 快速入门

这篇具有很好参考价值的文章主要介绍了gitbook 快速入门。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Gitbook 快速入门


1. 介绍

Gitbook 是一款优秀的 基于 Node.js 的开源文档管理工具,具有丰富的开源插件。

GitBook 支持 Markdown 和 AsciiDoc 两种语法格式,能够输出 html,pdf,epub,mobi 等多种格式。

2. 条件

nodejs 安装 node一定要安装10.X版本,否则报如下错误:

CLI version: 2.3.2
Installing GitBook 3.2.3
/usr/local/node/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287
      if (cb) cb.apply(this, arguments)
                 ^

TypeError: cb.apply is not a function
    at /usr/local/node/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
    at FSReqCallback.oncomplete (fs.js:193:5)

系统:ubuntu:18.04

3. gitbook 安装

$ npm install gitbook-cli -g
/usr/local/node/bin/gitbook -> /usr/local/node/lib/node_modules/gitbook-cli/bin/gitbook.js
+ gitbook-cli@2.3.2
added 578 packages from 672 contributors in 191.662s

#找到gitbook命令位置
$ ls /usr/local/node-v10.24.0-linux-x64/bin/
gitbook            node               node_modules/      npm                npx                package-lock.json

#添加软连接
$ ln -s /usr/local/node-v10.24.0-linux-x64/bin/gitbook /usr/local/bin/

$ ln -s /usr/local/node-v10.24.0-linux-x64/bin/book /usr/local/bin/

$ gitbook -V
CLI version: 2.3.2
Installing GitBook 3.2.3
gitbook@3.2.3 ../../../../tmp/tmp-117466TKiRhUq3ov0O/node_modules/gitbook
├── escape-html@1.0.3
├── escape-string-regexp@1.0.5
├── destroy@1.0.4
├── ignore@3.1.2
├── bash-color@0.0.4
├── gitbook-plugin-livereload@0.0.1
├── cp@0.2.0
├── nunjucks-do@1.0.0
├── graceful-fs@4.1.4
├── github-slugid@1.0.1
├── direction@0.1.5
├── q@1.4.1
├── spawn-cmd@0.0.2
├── gitbook-plugin-fontsettings@2.0.0
├── open@0.0.5
├── is@3.3.0
├── object-path@0.9.2
├── extend@3.0.2
├── json-schema-defaults@0.1.1
├── gitbook-plugin-search@2.2.1
├── jsonschema@1.1.0
├── crc@3.4.0
├── urijs@1.18.0
├── semver@5.1.0
├── immutable@3.8.2
├── front-matter@2.3.0
├── npmi@2.0.1 (semver@4.3.6)
├── resolve@1.1.7
├── gitbook-plugin-theme-default@1.0.7
├── moment@2.13.0
├── npm@3.9.2
├── dom-serializer@0.1.0 (domelementtype@1.1.3, entities@1.1.2)
├── tmp@0.0.28 (os-tmpdir@1.0.2)
├── error@7.0.2 (xtend@4.0.2, string-template@0.2.1)
├── omit-keys@0.1.0 (isobject@0.2.0, array-difference@0.0.1)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── js-yaml@3.14.1 (esprima@4.0.1, argparse@1.0.10)
├── gitbook-plugin-lunr@1.2.0 (html-entities@1.2.0, lunr@0.5.12)
├── gitbook-plugin-highlight@2.0.2 (highlight.js@9.2.0)
├── gitbook-plugin-sharing@1.0.2 (lodash@3.10.1)
├── i18n-t@1.0.1 (lodash@4.17.21)
├── gitbook-markdown@1.3.2 (kramed-text-renderer@0.2.1, gitbook-html@1.3.3, kramed@0.5.6, lodash@4.17.21)
├── gitbook-asciidoc@1.2.2 (gitbook-html@1.3.3, asciidoctor.js@1.5.5-1, lodash@4.17.21)
├── 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, mime@1.3.4, debug@2.2.0, http-errors@1.3.1, on-finished@2.3.0)
├── fresh-require@1.0.3 (is-require@0.0.1, shallow-copy@0.0.1, astw@1.3.0, acorn@0.9.0, sleuth@0.1.1, escodegen@1.14.3, through2@0.6.5)
├── rmdir@1.2.0 (node.flow@1.2.3)
├── 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.11.0, isstream@0.1.2, json-stringify-safe@5.0.1, tough-cookie@2.2.2, node-uuid@1.4.8, qs@6.1.2, hawk@3.1.3, combined-stream@1.0.8, mime-types@2.1.34, http-signature@1.1.1, form-data@1.0.1, bl@1.1.2, har-validator@2.0.6)
├── read-installed@4.0.3 (debuglog@1.0.1, util-extend@1.0.3, slide@1.1.6, readdir-scoped-modules@1.1.0, read-package-json@2.1.2)
├── cpr@1.1.1 (rimraf@2.4.5)
├── tiny-lr@0.2.1 (parseurl@1.3.3, livereload-js@2.4.0, qs@5.1.0, debug@2.2.0, faye-websocket@0.10.0, body-parser@1.14.2)
├── cheerio@0.20.0 (entities@1.1.2, lodash@4.17.21, css-select@1.2.0, htmlparser2@3.8.3, jsdom@7.2.2)
├── juice@2.0.0 (deep-extend@0.4.2, slick@1.12.2, batch@0.5.3, cssom@0.3.1, cross-spawn-async@2.2.5, commander@2.9.0, web-resource-inliner@2.0.0)
├── chokidar@1.5.0 (async-each@1.0.3, path-is-absolute@1.0.1, inherits@2.0.4, 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 version: 3.2.3

4. gitbook 创建

$ mkdir gitbook-demo
$ cd gitbook-demo

#使用 gitbook init 初始化书籍目录
$ gitbook init 
warn: no summary file in this book 
info: create README.md 
info: create SUMMARY.md 
info: initialization is finished 

$ ls 
README.md  SUMMARY.md
#使用 gitbook build 编译书籍
$ gitbook build
info: 7 plugins are installed 
info: 6 explicitly listed 
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 1 pages 
info: found 0 asset files 
info: >> generation finished with success in 0.4s ! 


$ ls
_book  README.md  SUMMARY.md

$ ls _book/
gitbook  index.html  search_index.json

$ ls _book/gitbook/
fonts  gitbook.js  gitbook-plugin-fontsettings  gitbook-plugin-highlight  gitbook-plugin-lunr  gitbook-plugin-search  gitbook-plugin-sharing  images  style.css  theme.js

#使用 gitbook serve 编译并预览书籍
$ 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 1 pages 
info: found 0 asset files 
info: >> generation finished with success in 0.5s ! 

Starting server ...
Serving book on http://localhost:4000

效果
gitbook 快速入门
图中侧栏Introduction的内容正是README.md的内容,SUMMARY.md 是编写界面侧栏的目录结构。

$ cat README.md 
# Introduction

$ cat SUMMARY.md 
# Summary

* [Introduction](README.md)

5. SUMMARY.md

GitBook 使用文件 SUMMARY.md 来定义书本的章节和子章节的结构。文件 SUMMARY.md 被用来生成书本内容的预览表。
SUMMARY.md 的格式是一个简单的链接列表,链接的名字是章节的名字,链接的指向是章节文件的路径。子章节被简单的定义为一个内嵌于父章节的列表。以 # 开头的行为注释被忽略。
GitBook使用一个SUMMARY.md文件来定义文档的菜单。
虽说在官方文档中,它是可选的,但是它相当重要,控制了左边菜单栏的显示内容。它通过 Markdown 中的列表语法来表示文件的父子关系。紧凑型的。

创建一个目录,并编写一个markdown格式的文档

$ mkdir git
$ mv git_training.md git
$ ls
_book  book.json  book.json_bak  git  kubernetes  node_modules  README.md  SUMMARY.md
$ ls git/
1_git_introduce.md  2_git_command.md

编写SUMMARY.md

# Summary
  
## 前言

* [Introduction](README.md)

## git

* [git 介绍](git/1_git_introduce.md)
  * [git 命令](git/2_git_training.md)

启动

$ gitbook serve

效果:
gitbook 快速入门
当 md 文件数量非常多时,我们可以利用 插件 summary 自动生成菜单 summary 文件的介绍。

6. README.md

书本的首页内容默认是从文件 README.md 中提取的。

README.md是 gitbook 最基础的文件之一,它一般用来描述这本书最基本的信息。 它呈现给读者这本书最初的样子,如果内容不够简洁明了,很可能就没有看下去的欲望了。

可以通过 gitbook init 自动创建该文件。

如果这个文件名没有出现在 SUMMARY.md (目录索引文件) 中,那么它会被添加为章节的第一个条目。

如何替代README.md

一些项目更愿意将 README.md 文件作为项目的介绍而不是书的介绍。

大部分代码托管平台将 README.md 自动显示到项目首页,如果你不喜欢这样。 从GitBook >2.0.0 起,就可以在 book.json 中定义某个文件作为README

删除掉SUMMARY.md文档关于README.md的引用
编写information.md

$ cat information.md 
---
这是一本关于介绍git、github、gitlab、gitbook的书籍。

比起官方的理解,它更接近体验训练。

book.json添加structure参数

book.json
{
    "structure" : {
        "readme" : "information.md"
    }
}

启动

$ gitbook serve

效果:默认的首页
gitbook 快速入门

7. book.json

7.1 侧栏添加链接

$ ls
_book  book.json  kubernetes  README.md  SUMMARY.md

$ vim book.json
{
    "author": "zongxun <me@zongxun.cn>",
    "description": "This is a sample book created by gitbook",
    "extension": null,
    "generator": "site",
    "links": {
        "sharing": {
            "all": null,
            "facebook": null,
            "google": null,
            "twitter": null,
            "weibo": null
        },
        "sidebar": {
            "Blog": "https://blog.csdn.net/xixihahalelehehe?spm=1000.2115.3001.5343"
        }
    },
    "output": null,
    "pdf": {
        "fontSize": 12,
        "footerTemplate": null,
        "headerTemplate": null,
        "margin": {
            "bottom": 36,
            "left": 62,
            "right": 62,
            "top": 36
        },
        "pageNumbers": false,
        "paperSize": "a4"
    },
    "plugins": [],
    "title": "GitBook Handbook",
    "variables": {}
}

$ 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 1 pages 
info: found 0 asset files 
info: >> generation finished with success in 0.5s ! 

Starting server ...
Serving book on http://localhost:4000

效果,只看到了一个Blog链接。
gitbook 快速入门

7.2 添加一个插件

编写book.json添加新theme-comscore颜色插件

$ cat book.json
{
    "author": "zongxun <me@zongxun.cn>",
    "description": "This is a sample book created by gitbook",
    "extension": null,
    "generator": "site",
    "links": {
        "sharing": {
            "all": null,
            "facebook": null,
            "google": null,
            "twitter": null,
            "weibo": null
        },
        "sidebar": {
            "Blog": "https://blog.csdn.net/xixihahalelehehe?spm=1000.2115.3001.5343"
        }
    },
    "output": null,
    "pdf": {
        "fontSize": 12,
        "footerTemplate": null,
        "headerTemplate": null,
        "margin": {
            "bottom": 36,
            "left": 62,
            "right": 62,
            "top": 36
        },
        "pageNumbers": false,
        "paperSize": "a4"
    },
    "plugins": [
     "theme-comscore" 
    ],
    "title": "GitBook Handbook",
    "variables": {}
}

安装插件

gitbook install
info: installing 1 plugins using npm@3.9.2 
info:  
info: installing plugin "theme-comscore" 
info: install plugin "theme-comscore" (*) from NPM with version 0.0.3 
/root/github/gitbook-demo
└── gitbook-plugin-theme-comscore@0.0.3 

info: >> plugin "theme-comscore" installed with success 
 

执行

$  gitbook serve

添加主题插件前:
gitbook 快速入门
添加主题插件后:
gitbook 快速入门文章来源地址https://www.toymoban.com/news/detail-468905.html

到了这里,关于gitbook 快速入门的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 用GitBook制作自己的网页版电子书

    前言 几年前阅读过其他人用GitBook创建的文档,可以直接在浏览器中打开,页面干净整洁,非常清爽,至今印象深刻。 GitBook非常适合用来为个人或团队制作文档,对于我这种偶尔写博客的人群来说,GitBook可以说是一款神器。我后续打算用GitBook来整理一些可以归纳到一个系列

    2024年02月04日
    浏览(28)
  • 超级详细GitBook和GitLab集成步骤【linux环境】

    本文主要是在 gitlab 上集成 gitbook 实现提交时 gitbook 自动刷新部署 ,以及在 linux 环境上搭建 gitlab gitbook,集成 GitLab CI 实现一个企业级或个人的 Wiki 系统 1.一台 linux 服务器 2.安装 node 以及 npm 环境 (这里注意 node 环境不要过高 不然在安装 gitbook 时会有报错 推荐:v12.16.3) 在 root

    2024年02月09日
    浏览(46)
  • windows服务器实用(6)——gitbook安装与部署

    为了查找方便,以下内容来自GPT GitBook是一个基于Git的文档编写和托管平台,它提供了一种方便易用的方式来创建、编辑、发布和托管文档,特别适合于技术文档、教程、手册等领域的文档编写和发布。 GitBook平台支持多种文档格式,包括Markdown、Asciidoc和reStructuredText等,同时

    2024年02月07日
    浏览(43)
  • Gitbook超详细使用教程,搭建属于你自己的博客!

    Gitbook 是一个平台,允许用户创建和分享内容丰富的在线书籍。它有一个用户友好的界面,可以快速地写作、编辑和发布你的电子书。这里是一个按照 Gitbook 的基本步骤 打开GitBook官网,这里我选择使用github账号来登录,当然你也可以自己新建一个账号 点击左下角的加号,选

    2024年02月04日
    浏览(37)
  • 网络拓扑结构入门快速介绍

    (1)一层交换机是指工作于OSI模型的第1层(物理层)只支持物理层协议的交换机(例如电话程控交换机); (2)二层交换机是指工作于OSI模型的第2层(数据链路层)支持物理层和数据链路层协议的交换机 例如以太网交换机); (3)三层交换机是指工作在OSI网络标准模型

    2024年02月16日
    浏览(49)
  • Prometheus介绍安装和快速入门

    1.1 什么是 Prometheus? Prometheus(普罗米修斯)是古希腊的一个神明,名字的意思是「先见之明」。从它的名字可以看出, Prometheus 是做「先见之明」的监控告警用途。维基百科简单写了它的作用:Prometheus is a free software application used for event monitoring and alerting(Prometheus 是用来监控

    2024年02月10日
    浏览(37)
  • Gin 框架介绍与快速入门

    目录 Gin 框架介绍与快速入门 一、Gin框架介绍 1. 快速和轻量级 2. 路由和中间件 3. JSON解析 4. 支持插件 5. Gin相关文档 二、基本使用 1.安装 2.导入 3.第一个Gin 应用 三、应用举例 四、Gin 入门核心 1.gin.Engine 2.gin.Context Gin是一个轻量级的Go语言Web框架,它具有高性能和简洁的设计

    2024年02月03日
    浏览(45)
  • 制造领域 基础概念快速入门介绍

    目录 1、基本背景知识  2、什么是BOM? 3、BOM有什么作用? 4、BOM有哪些形式? 4.1    按照用途划分 工程BOM——EBOM(Engineering BOM): 计划BOM——PBOM(Plan BOM): 设计BOM——DBOM(Design BOM): 制造BOM——MBOM(Manufacturing BOM): 客户BOM——CBOM(Customer BOM): 销售BOM——SBOM(SALE BOM): 维修

    2024年01月20日
    浏览(43)
  • Spring Cloud 快速入门基本介绍

    😀前言 本篇博文是关于Spring Cloud 基本介绍,希望你能够喜欢 🏠个人主页:晨犀主页 🧑个人简介:大家好,我是晨犀,希望我的文章可以帮助到大家,您的满意是我的动力😉😉 💕欢迎大家:这里是CSDN,我总结知识的地方,欢迎来到我的博客,感谢大家的观看🥰 如果文

    2024年02月10日
    浏览(35)
  • 思通舆情 是一款开源免费的舆情系统 介绍

    思通舆情 是一款开源免费的舆情系统。 支持本地化部署,支持在线体验。 支持对海量舆情数据分析和挖掘。 无论你是使用者还是共同完善的开发者,欢迎 pull request 或者 留言对我们提出建议。 您的支持和参与就是我们坚持开源的动力!请   star 或者 fork! 思通舆情 的功能

    2024年04月13日
    浏览(58)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包