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:
parent
660cbfa6ce
commit
8622d058d5
|
@ -109,6 +109,7 @@ edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path
|
||||||
site-url = "/example-book/"
|
site-url = "/example-book/"
|
||||||
cname = "myproject.rs"
|
cname = "myproject.rs"
|
||||||
input-404 = "not-found.md"
|
input-404 = "not-found.md"
|
||||||
|
no-copy-extra-files = false
|
||||||
```
|
```
|
||||||
|
|
||||||
The following configuration options are available:
|
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
|
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
|
required by GitHub Pages (see [*Managing a custom domain for your GitHub Pages
|
||||||
site*][custom domain]).
|
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
|
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
|
||||||
|
|
||||||
|
|
|
@ -582,6 +582,8 @@ pub struct HtmlConfig {
|
||||||
/// The mapping from old pages to new pages/URLs to use when generating
|
/// The mapping from old pages to new pages/URLs to use when generating
|
||||||
/// redirects.
|
/// redirects.
|
||||||
pub redirect: HashMap<String, String>,
|
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 {
|
impl Default for HtmlConfig {
|
||||||
|
@ -610,6 +612,7 @@ impl Default for HtmlConfig {
|
||||||
cname: None,
|
cname: None,
|
||||||
live_reload_endpoint: None,
|
live_reload_endpoint: None,
|
||||||
redirect: HashMap::new(),
|
redirect: HashMap::new(),
|
||||||
|
no_copy_extra_files: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -627,9 +627,16 @@ impl Renderer for HtmlHandlebars {
|
||||||
self.emit_redirects(&ctx.destination, &handlebars, &html_config.redirect)
|
self.emit_redirects(&ctx.destination, &handlebars, &html_config.redirect)
|
||||||
.context("Unable to emit redirects")?;
|
.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
|
// 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue