diff --git a/guide/src/format/configuration/renderers.md b/guide/src/format/configuration/renderers.md index 7e743014..e56484a4 100644 --- a/guide/src/format/configuration/renderers.md +++ b/guide/src/format/configuration/renderers.md @@ -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 diff --git a/src/config.rs b/src/config.rs index 7f56e797..c8ca1b67 100644 --- a/src/config.rs +++ b/src/config.rs @@ -582,6 +582,8 @@ pub struct HtmlConfig { /// The mapping from old pages to new pages/URLs to use when generating /// redirects. pub redirect: HashMap, + /// 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, } } } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 8ea2f49e..b5c513bd 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -627,9 +627,16 @@ impl Renderer for HtmlHandlebars { self.emit_redirects(&ctx.destination, &handlebars, &html_config.redirect) .context("Unable to emit redirects")?; - // 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"])?; - + 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"], + )?; + } Ok(()) } }