Skip to content

Commit 732a67a

Browse files
committed
Add documentation and unit tests for .mdbookignore
1 parent f144b57 commit 732a67a

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

guide/src/format/configuration/renderers.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ The value can be any valid URI the browser should navigate to (e.g. `https://rus
279279
This will generate an HTML page which will automatically redirect to the given location.
280280
Note that the source location does not support `#` anchor redirects.
281281

282+
### `[.mdbookignore]`
283+
284+
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.
285+
286+
For example:
287+
```
288+
*.rs
289+
/target/
290+
```
291+
282292
## Markdown Renderer
283293

284294
The Markdown renderer will run preprocessors and then output the resulting

src/book/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ fn preprocessor_should_run(
587587
mod tests {
588588
use super::*;
589589
use std::str::FromStr;
590+
use tempfile::Builder as TempFileBuilder;
590591
use toml::value::{Table, Value};
591592

592593
#[test]
@@ -856,4 +857,21 @@ mod tests {
856857
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg);
857858
assert_eq!(got, should_be);
858859
}
860+
861+
#[test]
862+
fn build_test_book() {
863+
let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir().unwrap();
864+
let test_book_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_book");
865+
866+
utils::fs::copy_files_except_ext(&test_book_dir, temp_dir.path(), true, None, None)
867+
.expect("Error while copying test book to temp dir");
868+
869+
let book = MDBook::load(temp_dir.path()).expect("Unable to load book");
870+
book.build().expect("Error while building book");
871+
872+
let book_dir = temp_dir.path().join("book");
873+
assert!(book_dir.join("index.html").exists());
874+
assert!(book_dir.join(".mdbookignore").exists());
875+
assert!(!book_dir.join("ignored_file").exists());
876+
}
859877
}

test_book/src/.mdbookignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignored_file

test_book/src/ignored_file

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This will not be copied to the book directory.

0 commit comments

Comments
 (0)