mdBook入门
安装
下载地址:https://github.com/rust-lang/mdBook/releases
liunx版本(AI解释)
- gnu:指的是使用了GNU C Library(glibc)
- musl:指的是使用了musl C Library
我下的GNU
mkdir -p /home/qingchen/tools/mdbook
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.43/mdbook-v0.4.43-x86_64-unknown-linux-gnu.tar.gz
tar -xz --directory=/home/qingchen/tools/mdbook
sudo ln -s /home/qingchen/tools/mdbook/mdbook /usr/bin/mdbook
mdbook
####
Creates a book from markdown files
Usage: mdbook [COMMAND]
Commands:
init Creates the boilerplate structure and files for a new book
build Builds a book from its markdown files
test Tests that a book's Rust code samples compile
clean Deletes a built book
completions Generate shell completions for your shell to stdout
watch Watches a book's files and rebuilds it on changes
serve Serves a book at http://localhost:3000, and rebuilds it on changes
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
For more information about a specific command, try `mdbook <command> --help`
The source code for mdBook is available at: https://github.com/rust-lang/mdBook
Creating a Book
https://rust-lang.github.io/mdBook/guide/creating.html
mdbook init mdbook-demo
####
qingchen@liqingchen:~/workspace/projects$ mdbook init mdbook-demo
Do you want a .gitignore to be created? (y/n)
y
What title would you like to give the book?
qingchen-mdbook-demo
2024-12-29 21:24:20 [INFO] (mdbook::book::init): Creating a new book with stub content
All done, no errors...
cd mdbook-demo
mdbook serve --open
mdbook build
Deploy
mkdir -p .github/workflows/
touch mdbook.yml
然后写入下面的内容是github action的工作流:
# Sample workflow for building and deploying a mdBook site to GitHub Pages
#
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
#
name: Deploy mdBook site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.4.36
steps:
- uses: actions/checkout@v4
- name: Install mdBook
run: |
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
rustup update
cargo install --version ${MDBOOK_VERSION} mdbook
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Build with mdBook
run: mdbook build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./book
# Deployment job
deploy:
environment:
name: github-pages
url: $
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
然后把项目上传到Github会自动执行action,大概不到3分钟可以访问了
https://qingchen177.github.io/mdbook-demo/
END
项目Demo地址:https://github.com/qingchen177/mdbook-demo
不适合做Blog网站,但是做书是极好用的。