2020-04-04 start to use mdbook to write my blog
download and install mdbook
refer to mdbook@github
cargo install mdbook
create a book
mkdir ~/d/working/wcy123.github.com/
mdbook init
I modifiy book.toml
as following, copy some configurations from mdBook/book-example/book.toml
[book]
authors = ["WangChunye"]
language = "cn"
multilingual = true
src = "src"
title = "Wang Chunye"
[output.html]
mathjax-support = true
google-analytics = "UA-98267158-1"
[output.html.playpen]
editable = true
line-numbers = true
[output.html.search]
limit-results = 20
use-boolean-and = true
boost-title = 2
boost-hierarchy = 2
boost-paragraph = 1
expand = true
heading-split-level = 2
We can include another file by using a preprocessor, the above is generated by
```toml
{{#include ../book.toml}}
```
refer to mdBook-specific markdown for detail
start the server
mdbook serve
open http://localhost:3000
MathJax support
block equations
\[ (a+b)^2 = a^2 + 2ab + b^2 \]
where \( (a+b)^2 = a^2 + 2ab + b^2 \) is an inline equations
refer to MathJax Support for detail
source code syntax high light
#include <stdio.h>
int main(int argc, char* argv[]) {
printf("hello world\n");
}
#![allow(unused_variables)] fn main() { fn foo() -> i32 { 1 + 1 } }
CI integration and deploy automation
-
create a github token
refer to creating a token. for detail.
-
enable travis ci
refer to https://travis-ci.org/github/
activate Travis CI and set environment variable GITHUB_TOKEN to your token.
read secure your token
-
deploy automation
read Running mdbook in Continuous Integration and GitHub Pages Deployment
edit <PROJECT_ROOT>/.travis.yml
language: rust
sudo: false
cache:
- cargo
rust:
- stable
before_script:
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.3" mdbook)
- cargo install-update -a
script:
- mdbook build . && mdbook test .
deploy:
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
local-dir: book
keep-history: false
target_branch: master
on:
branch: pandoc
NOTE: we must set the local-dir
to book
which is the output directory of mdbook
theme
# get the default theme
mkdir -p $HOME/tmp/book
cd $HOME/tmp/book
mdbook init --theme
cd - # go back to your book directory
cp -av $HOME/tmp/book/src/theme ./ # copy default theme
curl -sLo src/theme/highlight.css cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/solarized-light.min.css
NOTE: it is confusing whether the theme directory is ./theme
or ./src/theme
, it seems ./theme
is preferred.