Add documentation and unit tests for `.mdbookignore`

This commit is contained in:
Bergmann89 2022-10-17 10:40:00 +02:00
parent 1799d4075e
commit fcf98be339
4 changed files with 31 additions and 1 deletions

View File

@ -298,6 +298,16 @@ The value can be any valid URI the browser should navigate to (e.g. `https://rus
This will generate an HTML page which will automatically redirect to the given location.
Note that the source location does not support `#` anchor redirects.
### `[.mdbookignore]`
You can use a `.mdbookignore` file to exclude files from the build process. The file is places in the `src` directory of your book and has the format known from [`.gitignore`](https://git-scm.com/docs/gitignore) files.
For example:
```
*.rs
/target/
```
## Markdown Renderer
The Markdown renderer will run preprocessors and then output the resulting

View File

@ -610,7 +610,8 @@ fn preprocessor_should_run(
mod tests {
use super::*;
use std::str::FromStr;
use toml::value::Table;
use tempfile::Builder as TempFileBuilder;
use toml::value::{Table, Value};
#[test]
fn config_defaults_to_html_renderer_if_empty() {
@ -879,4 +880,21 @@ mod tests {
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg);
assert_eq!(got, should_be);
}
#[test]
fn build_test_book() {
let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir().unwrap();
let test_book_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_book");
utils::fs::copy_files_except_ext(&test_book_dir, temp_dir.path(), true, None, None)
.expect("Error while copying test book to temp dir");
let book = MDBook::load(temp_dir.path()).expect("Unable to load book");
book.build().expect("Error while building book");
let book_dir = temp_dir.path().join("book");
assert!(book_dir.join("index.html").exists());
assert!(book_dir.join(".mdbookignore").exists());
assert!(!book_dir.join("ignored_file").exists());
}
}

View File

@ -0,0 +1 @@
ignored_file

View File

@ -0,0 +1 @@
This will not be copied to the book directory.