Skip to content

Commit

Permalink
Add documentation and unit tests for .mdbookignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Bergmann89 committed Oct 17, 2022
1 parent f144b57 commit 732a67a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,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 form 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
Expand Down
18 changes: 18 additions & 0 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ fn preprocessor_should_run(
mod tests {
use super::*;
use std::str::FromStr;
use tempfile::Builder as TempFileBuilder;
use toml::value::{Table, Value};

#[test]
Expand Down Expand Up @@ -856,4 +857,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());
}
}
1 change: 1 addition & 0 deletions test_book/src/.mdbookignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignored_file
1 change: 1 addition & 0 deletions test_book/src/ignored_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This will not be copied to the book directory.

0 comments on commit 732a67a

Please sign in to comment.