From 20eacd2976b0b81b3e51e09c66ebea3109687760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Fri, 22 Oct 2021 16:11:57 +0200 Subject: [PATCH] Include `src/README.md` as prefix chapter with `--auto-summary`. --- src/book/summary.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/book/summary.rs b/src/book/summary.rs index ca3224e7..2f7ae08d 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -76,6 +76,7 @@ impl Summary { /// The file/folder name is used to compose the chapter's link. /// /// Chapters are added to the book in alphabetical order, using the file/folder name. + /// If a `src_dir/README.md` file is present, it is included as a prefix chapter. pub fn from_sources>(src_dir: P) -> std::io::Result { let mut summary = Summary { title: None, @@ -144,6 +145,13 @@ impl Summary { } } + // Special case for the `src/README.md` file. + let root_readme_path = src_dir.as_ref().join("README.md"); + if root_readme_path.is_file() { + let link = Link::new_unnamed(root_readme_path); + summary.prefix_chapters.push(SummaryItem::Link(link)) + } + summary.numbered_chapters = read_dir(src_dir)?; number_items(&mut summary.numbered_chapters, &[]);