Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions config/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct DocConfig {
pub title: String,
/// Path to user provided `book.toml`.
pub book: PathBuf,
/// Path to user provided welcome markdown (default is Readme.md)
pub homepage: PathBuf,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah so this is expected to be set in the toml file?

I think this should be an Option

/// The repository url.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub repository: Option<String>,
Expand All @@ -24,6 +26,7 @@ impl Default for DocConfig {
Self {
out: PathBuf::from("docs"),
book: PathBuf::from("book.toml"),
homepage: PathBuf::from("README.md"),
title: String::default(),
repository: None,
ignore: Vec::default(),
Expand Down
30 changes: 22 additions & 8 deletions doc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,33 @@ impl DocBuilder {
fs::create_dir_all(&out_dir_src)?;

// Write readme content if any
let readme_content = {
let homepage_content = {

let src_readme = self.sources.join(Self::README);
let root_readme = self.root.join(Self::README);
if src_readme.exists() {
fs::read_to_string(src_readme)?
} else if root_readme.exists() {
fs::read_to_string(root_readme)?
} else {
String::new()

//Check to see if there is a 'homepage' option specified in config.
//If not, fall back to src and root readme files.
let homepage_path = {
if self.config.homepage.is_file() {
Some(self.config.homepage.clone())
} else if src_readme.exists() {
Some(src_readme)
}else if root_readme.exists() {
Some(root_readme)
}else {
None
}
};

match homepage_path {
Some(path) => fs::read_to_string(path)?,
None => String::new(),
}

@mattsse mattsse Apr 6, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read that correctly then these changes are not needed if we set the src_readme:

let root_readme = self.homepage.as_ref().map(|homepage|self.root.join(homepage)).unwrap_or_else(||self.root.join(Self::README);

};
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