Introduction to mdBook

mdBook is a command-line tool written in Rust and used to create books in Markdown. It is ideal for creating product or API documentation, tutorials, course materials, or any presentation that needs to be concise, easy to navigate, and customizable. The functionality is similar to Gitbook, and the biggest advantage is speed.

  • Lightweight, Markdown syntax
  • Search, integrated search function
  • Syntax highlighting, syntax highlighting
  • Multiple themes, Theme custom output format
  • Preprocessor, support preprocessor support, extensions to modify markdown renderer before it
  • Backend, Backends supports multiple output formats
  • Speed, Rust development, speed is unbeatable
  • Even, Rust code automated testing.

Install mdBook

Since mdBook is developed in Rust, we need to install Rust in advance

Install Rust

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
......
Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"
# cargo version
cargo 1.65.0 (4bc8f24d3 2022-10-20)

After installing Rust, build and install mdBook on the command line. After the installation is complete:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# cargo install mdbook
Updating crates.io index
Installing mdbook v0.4.21
Downloaded os_str_bytes v6.4.0 Downloaded chrono v0.4.23 Downloaded 2 crates (210.4 KB) in 1.30s ...... Compiling libc v0.2.137 Compiling mdbook v0.4.21 Finished release [optimized] target(s) in 1m 12s Installing /Users/wanzi/.cargo/bin/mdbook Installed package `mdbook v0.4.21` utable `mdbook`) #This indicates that the installation has been successful # mdbook --version mdbook v0.4.21 # tree -L 2 ~/.cargo /Users/wanzi/.cargo ├── bin │ ├── cargo │ ├── cargo-clippy │ ├── cargo-fmt │ ├── cargo-miri │ ├── clippy-driver
│   ├── mdbook #This means that the installation is complete
│   ├── rls
│   ├── rust-gdb
│   ├── rust-gdbgui
│   ├── rust-lldb
│   ├── rustc
│   ├── rustdoc
│   ├── rustfmt
│   └── rustup
├── env
└── registry
├── CACHEDIR.TAG
├── cache
├── index
└── src

Of course, if you need the latest version, you can use the following method:

1
cargo install --git https://github.com/rust-lang/mdBook.git mdbook

Use MdBook to write an e-book

Initialize and generate a book named devops-manual:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# mdbook init devops-manual
Do you want a .gitignore to be created? (y/n)
y
What title would you like to give the book?
devops-manual
2022-10-06 13:59:33 [INFO] (mdbook::book::init): Creating a new book with stub content

All done, no errors...
# tree devops-manual
devops-manual
├── book
├── book.toml
└── src
├── SUMMARY.md
└── chapter_1.md

2 directories, 3 files

Start mdbook and test the local preview: ```shell # mdbook serve –open 2022-10-06 14:04:05 [INFO] (mdbook::book): Book building has started 2022-10-06 14:04: 05 [INFO] (mdbook::book): Running the html backend 2022-10-06 14:04:05 [INFO] (mdbook::cmd::serve): Serving on: http://localhost:3000 2022- 10-06 14:04:05 [INFO] (mdbook): Opening web browser 2022-10-06 14:04:05 [INFO] (warp::server): Server::run; addr=127.0.0.1:3000 2022-10-06 14:04:05 [INFO] (warp::server): listening on http://127.0.0.1:3000 2022-10-06 14:04:05 [INFO] (mdbook::cmd::watch): Listening for changes…

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

The --open option will open the default web browser to view the new book. For the generated mdBook new book directory structure:

- book.toml: describes how to build the e-book settings, written in TOML syntax- SUMMARY.md : Located in src/SUMMARY.md, this file contains a list of all chapters in the book. Before viewing a chapter, you must add it to this list.
- src: This directory stores the source files of the book. Each chapter has a separate Markdown file - book: stores e-book HTML files. When you build a book (mdbook build), e-book static files will be generated in this directory for hosting on other web services, such as Github Pages.

At this point, if we want to write an e-book about DevOps, we only need to write the table of contents and then write each chapter one by one.

For example, here is mine: devops-manual/SUMMARY.md
```yaml
# Summary

[Introduction](README.md)

# DevOps Project - [DevOps](xops/devops.md)

# DevOps Tool Chain - [Basic Tools]( base/readme.md)
- [Git](base/git.md)
- [Docker](base/docker.md)
- [Makefile](base/makefile.md)

- [Product Requirements](project/readme.md )
- [Jira](project/jira.md)
- [PingCode](project/jira.md)

- [Code Management](code/readme.md)
- [Gitlab](code/gitlab.md)
- [Github] (code/github.md)
- [Gerrit](code/Gerrit.md)

- [Test Security Scan](test/readme.md)
- [Jmeter](test/jmeter.md)
- [SnoarQube](test/snoarqube.md)
- [BlackDuck](test/blackduck.md)
- [Fortify]( test/fortify.md)

- [Compile and Build](makebuild/readme.md)
- [Maven](makebuild/maven.md)
- [Gradle](makebuild/gradle.md)
- [Node](makebuild/node.md )
- [Npm](makebuild/npm.md)
- [Cargo](makebuild/cargo.md)

- [Product Warehouse](hub/readme.md)
- [Harbor](hub/harbor.md)
- [Nexus] (hub/nexus.md)
- [Jfrog artifactory](hub/jfrog.md)

- [Automated Deployment](autodeploy/readme.md)
- [Ansible](autodeploy/ansible.md)
- [ArgoCD](autodeploy/argocd.md)
- [Helm](autodeploy/ helm.md)
- [Kustomize](autodeploy/kustomize.md)
- [Log monitoring link](logmonitor/readme.md)
- [EFK](logmonitor/efk.md)
- [Prometheus](logmonitor/prometheus.md )
- [Grafana](logmonitor/grafana.md)
- [Loki](logmonitor/loki.md)
- [Skywalking](logmonitor/skywalking.md)
- [Jaeger](logmonitor/jadger.md)
- [Pinpoint](logmonitor/pinpoint.md) - [Other tools](others/readme.md) - [Rancher](others/rancher.md) - [Jumpserver](others/jumpserver.md) - [Nacos](others /nacos.md) - [Consul](others/consul.md) - [Trafik](others/apisix.md) - [Apisix](others/apisix.md) - [Terraform](others/terraform.md) - [Pulumi](others/pulumi.md) - [Valut](others/valut.md) - [Development language](language/readme.md) - [Shell](language/shell.md) - [Python](language /python.md) - [Golang](language/golang.md) - [Framework module](framework/readme.md) - [Gin](framework/gin.md) - [Vue](framework/vue.md) - [React-antd] (framework/antd.md) - [Django](framework/django.md) - [Bootstrap](framework/bootstrap.md) - [Swagger](framework/swagger.md) - [Postman](framework/postman.md ) - [ApiPost7](framework/apipost7.md) - [RBAC](framework/rbac.md) - [JWT](framework/jwt.md) - [XOPS](xops/xops.md) - [GitOps]( xops/gitops.md) - [AiOps](xops/aiops.md)
- [MLOps](xops/mlops.md)
- [FinOps](xops/finops.md)
- [DevSecOps](xops/devsecopsmd)
- [DevDBOps](xops/devdbops. md)
- [Chaos Engineering](xops/hundun.md)`

After completing the above writing work, you only need to build mdbook, then map the book directory to the nginx directory, and configure the virtual host. Isn’t it simple?