feat: add 'no-copy-extra-files' flag to html renderer, preventing extra files from being copied to the dest dir

This commit is contained in:
Sean P. Madden 2023-11-23 23:46:04 -05:00
parent 660cbfa6ce
commit 8622d058d5
No known key found for this signature in database
GPG Key ID: 68830AB1034AB2BE
3 changed files with 19 additions and 3 deletions

View File

@ -109,6 +109,7 @@ edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path
site-url = "/example-book/"
cname = "myproject.rs"
input-404 = "not-found.md"
no-copy-extra-files = false
```
The following configuration options are available:
@ -166,6 +167,11 @@ The following configuration options are available:
This string will be written to a file named CNAME in the root of your site, as
required by GitHub Pages (see [*Managing a custom domain for your GitHub Pages
site*][custom domain]).
- **no-copy-extra-files:** Defaults to `false`. Do not copy any extra files found in the `src` directory to the dest
directory, only copy those files generated by or interacted with by mdBook through the `SUMMARY.md` file. This
setting does not affect files specified in `additional-js` nor `additional-css`. Defaults to `false`. Enabling this
setting allows you to mix book-files alongside non-book files in the `src` directory without them getting copied to
the dest folder automatically.
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site

View File

@ -582,6 +582,8 @@ pub struct HtmlConfig {
/// The mapping from old pages to new pages/URLs to use when generating
/// redirects.
pub redirect: HashMap<String, String>,
/// Don't copy extra files from the src folder to the output folder
pub no_copy_extra_files: bool,
}
impl Default for HtmlConfig {
@ -610,6 +612,7 @@ impl Default for HtmlConfig {
cname: None,
live_reload_endpoint: None,
redirect: HashMap::new(),
no_copy_extra_files: false,
}
}
}

View File

@ -627,9 +627,16 @@ impl Renderer for HtmlHandlebars {
self.emit_redirects(&ctx.destination, &handlebars, &html_config.redirect)
.context("Unable to emit redirects")?;
if !html_config.no_copy_extra_files {
// Copy all remaining files, avoid a recursive copy from/to the book build dir
utils::fs::copy_files_except_ext(&src_dir, destination, true, Some(&build_dir), &["md"])?;
utils::fs::copy_files_except_ext(
&src_dir,
destination,
true,
Some(&build_dir),
&["md"],
)?;
}
Ok(())
}
}