# mdbook-collector A [mdbook preprocessor](https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html) which collects json/yaml/toml data from each post and builds a json file of it ## Install ``` cargo install mdbook-collector ``` ## Use (v0.2.0) In a markdown file of a post, include: ```html ``` Then the preprocessor will parse each post and build a consolidated json file, which is a map whose key is each post's **url path** and whose values are **sub-map** of parsed data. The title of each post will also be added to the sub-map, with a key name "title". ```json { "post/ex/url": { "title": "Title of this post", "data" { "type": "json", "keywords": ["json", "collect"] } }, ... } ``` * 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. And the title will be added to each sub map. This newly created json file can be used for various purposes: ex. in your additional .js files. Make sure that each post's raw json data should be able to be parsed into "map" structure. For example, below will not be parsed and thus be ignored: ```html ``` If Json's strictness and no-comment-ness bothers you, use yaml or toml option! ## Configuration Configuration example in `book.toml`. Below is default setting: ```toml [preprocessor.collector] input_type = "json" marker = "collect" save_path = "collect.json" add_title = true ``` ### input_type The output file is always in .json format. However you can select to-be-parsed input data's format among `json`, `yaml`, or `toml`. For example, using `toml`: ``` ``` The preprocessor depends on `serde_json` for json option, `serde_yaml` for yaml, and `toml` for toml. The `yaml` and `toml` options parse not only oneselves' format but also json format, as their dependant crates work in such ways. ### marker The preprocessor tries to parse any literal located between the first `` in each post's source file. (`