Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// The repository url.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub repository: Option<String>,
Expand All @@ -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(),
Expand Down
22 changes: 17 additions & 5 deletions doc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down