diff --git a/src/book/mod.rs b/src/book/mod.rs index de24e4c9..645d23c9 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -662,9 +662,10 @@ mod tests { let got = determine_preprocessors(&cfg); assert!(got.is_ok()); - assert_eq!(got.as_ref().unwrap().len(), 2); - assert_eq!(got.as_ref().unwrap()[0].name(), "index"); - assert_eq!(got.as_ref().unwrap()[1].name(), "links"); + assert_eq!(got.as_ref().unwrap().len(), 3); + assert_eq!(got.as_ref().unwrap()[0].name(), "drinks"); + assert_eq!(got.as_ref().unwrap()[1].name(), "index"); + assert_eq!(got.as_ref().unwrap()[2].name(), "links"); } #[test] diff --git a/src/preprocess/drinks.rs b/src/preprocess/drinks.rs index 7e756738..99255b17 100644 --- a/src/preprocess/drinks.rs +++ b/src/preprocess/drinks.rs @@ -56,17 +56,19 @@ impl Preprocessor for DrinkPreprocessor { fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result { let path = ctx.root.join("drinks.txt"); - let drinks: Dict = { - let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary")); - reader - .lines() - .filter_map(|l| { - l.expect("Cannot read line in drinks dictionary") - .split_once(SPLITTER) - .map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned())) - }) - .collect::>() - }; + if !path.exists() { + return Ok(book); + } + + let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary")); + let drinks: Dict = reader + .lines() + .filter_map(|l| { + l.expect("Cannot read line in drinks dictionary") + .split_once(SPLITTER) + .map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned())) + }) + .collect::>(); book.for_each_mut(|section: &mut BookItem| { if let BookItem::Chapter(ref mut ch) = *section {