summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2020-06-23 10:48:08 -0700
committerGitHub <noreply@github.com>2020-06-23 10:48:08 -0700
commit9268884b17ed6953ef5f7f736e0236b63e62566c (patch)
treedb692c81aef690c6bda7a732298f14b7bfe2b91c /src/config.rs
parent4f435c62e69e47685a4075e95ee765111ebf5746 (diff)
parentd7df832cceaaa07d1546d05b5474b3cb70190e77 (diff)
Merge pull request #1221 from manuel-woelker/fb-539-not-found-page
Generate 404.html page (#539)
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 8496370c..1389f139 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -504,6 +504,10 @@ pub struct HtmlConfig {
/// FontAwesome icon class to use for the Git repository link.
/// Defaults to `fa-github` if `None`.
pub git_repository_icon: Option<String>,
+ /// Input path for the 404 file, defaults to 404.md, set to "" to disable 404 file output
+ pub input_404: Option<String>,
+ /// Absolute url to site, used to emit correct paths for the 404 page, which might be accessed in a deeply nested directory
+ pub site_url: Option<String>,
/// This is used as a bit of a workaround for the `mdbook serve` command.
/// Basically, because you set the websocket port from the command line, the
/// `mdbook serve` command needs a way to let the HTML renderer know where
@@ -535,6 +539,8 @@ impl Default for HtmlConfig {
search: None,
git_repository_url: None,
git_repository_icon: None,
+ input_404: None,
+ site_url: None,
livereload_url: None,
redirect: HashMap::new(),
}
@@ -667,6 +673,7 @@ impl<'de, T> Updateable<'de> for T where T: Serialize + Deserialize<'de> {}
#[cfg(test)]
mod tests {
use super::*;
+ use crate::utils::fs::get_404_output_file;
const COMPLEX_CONFIG: &str = r#"
[book]
@@ -1001,4 +1008,31 @@ mod tests {
assert_eq!(cfg.book.title, Some(should_be));
}
+
+ #[test]
+ fn file_404_default() {
+ let src = r#"
+ [output.html]
+ destination = "my-book"
+ "#;
+
+ let got = Config::from_str(src).unwrap();
+ let html_config = got.html_config().unwrap();
+ assert_eq!(html_config.input_404, None);
+ assert_eq!(&get_404_output_file(&html_config.input_404), "404.html");
+ }
+
+ #[test]
+ fn file_404_custom() {
+ let src = r#"
+ [output.html]
+ input-404= "missing.md"
+ output-404= "missing.html"
+ "#;
+
+ let got = Config::from_str(src).unwrap();
+ let html_config = got.html_config().unwrap();
+ assert_eq!(html_config.input_404, Some("missing.md".to_string()));
+ assert_eq!(&get_404_output_file(&html_config.input_404), "missing.html");
+ }
}