diff --git a/guide/src/format/configuration/renderers.md b/guide/src/format/configuration/renderers.md index b9c3086114..d5a16d12b8 100644 --- a/guide/src/format/configuration/renderers.md +++ b/guide/src/format/configuration/renderers.md @@ -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 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 diff --git a/src/book/mod.rs b/src/book/mod.rs index 5ec64d7c3a..cfd327c453 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -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] @@ -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()); + } } diff --git a/test_book/src/.mdbookignore b/test_book/src/.mdbookignore new file mode 100644 index 0000000000..6a79f808a9 --- /dev/null +++ b/test_book/src/.mdbookignore @@ -0,0 +1 @@ +ignored_file diff --git a/test_book/src/ignored_file b/test_book/src/ignored_file new file mode 100644 index 0000000000..1ce1f71700 --- /dev/null +++ b/test_book/src/ignored_file @@ -0,0 +1 @@ +This will not be copied to the book directory.