mdbook-tagger
A mdbook preprocessor which collects and builds tag data in Json format.
Install
cargo install mdbook-tagger
Use (v0.2.0)
In a .md file of a post, include:
<!-- tags: computer; book -->
The preprocessor parses each post's tag data and then builds two consolidated json files:
(1) Tag to Posts
(2) Post to Tags
- Mind that in the v.0.1.0, the key of this map was post's name(title). From v.0.2.0, each post's url path is the key of map.
Configuration
Default setting (in book.toml
):
[]
= "tags"
= ";"
= "tag2posts.json"
= "post2tags.json"
marker
By default, the preprocessor tries to parse any literal located between the first <!-- tags
and -->
in each post's source file. (<!--tags
instead of <!-- tags
is ok.)
split
<!-- tags: computer; book; duck; -->
This will be parsed into tags of ["computer", "book", "duck"].
You can change the default seperator pattern ";".
If split = ",",
<!-- tags: computer, book, duck -->
will be parsed into tags of ["computer", "book", "duck"].
tag2posts_path, post2tags_path
The path where newly built json files will be saved.
Each json file will be saved at a path which combines book's src
directory and the given tag2posts_path
and post2tags_path
.
🪧 Mind that the
mdbook serve
watchessrc
directory. Once you startmdbook serve
command then change any contents undersrc
directory, the preprocessor will rebuild the json file and this leads to a repeat loop of watch and serve. To prevent this, make a .gitignore file at the book's root directory and add the to-be-built json file's name.