diff --git a/config/src/doc.rs b/config/src/doc.rs index 4e1952f35a631..2dfac01b4df44 100644 --- a/config/src/doc.rs +++ b/config/src/doc.rs @@ -12,6 +12,11 @@ pub struct DocConfig { pub title: String, /// Path to user provided `book.toml`. pub book: PathBuf, + /// Path to user provided welcome markdown. + /// + /// If none is provided, it defaults to `README.md`. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub homepage: Option, /// The repository url. #[serde(default, skip_serializing_if = "Option::is_none")] pub repository: Option, @@ -24,6 +29,7 @@ impl Default for DocConfig { Self { out: PathBuf::from("docs"), book: PathBuf::from("book.toml"), + homepage: Some(PathBuf::from("README.md")), title: String::default(), repository: None, ignore: Vec::default(), diff --git a/doc/src/builder.rs b/doc/src/builder.rs index e629caa053fc5..50c628f366254 100644 --- a/doc/src/builder.rs +++ b/doc/src/builder.rs @@ -231,19 +231,31 @@ impl DocBuilder { fs::create_dir_all(&out_dir_src)?; // Write readme content if any - let readme_content = { - let src_readme = self.sources.join(Self::README); + let homepage_content = { + // Default to the homepage README if it's available. + // If not, use the src README as a fallback. + let homepage_or_src_readme = self + .config + .homepage + .as_ref() + .map(|homepage| self.root.join(homepage)) + .unwrap_or_else(|| self.sources.join(Self::README)); + // Grab the root readme. let root_readme = self.root.join(Self::README); - if src_readme.exists() { - fs::read_to_string(src_readme)? + + //Check to see if there is a 'homepage' option specified in config. + //If not, fall back to src and root readme files, in that order. + if homepage_or_src_readme.exists() { + fs::read_to_string(homepage_or_src_readme)? } else if root_readme.exists() { fs::read_to_string(root_readme)? } else { String::new() } }; + let readme_path = out_dir_src.join(Self::README); - fs::write(&readme_path, readme_content)?; + fs::write(&readme_path, homepage_content)?; // Write summary and section readmes let mut summary = BufWriter::default();