Skip to content

improving docs generation by adding homepage to config#4702

Merged
mattsse merged 6 commits intofoundry-rs:masterfrom
ethereumdegen:improve-docs-generation
May 12, 2023
Merged

improving docs generation by adding homepage to config#4702
mattsse merged 6 commits intofoundry-rs:masterfrom
ethereumdegen:improve-docs-generation

Conversation

@ethereumdegen
Copy link
Contributor

@ethereumdegen ethereumdegen commented Apr 6, 2023

Motivation

When using the docs command, I wanted to be able to use a different README file for the 'home page' of the docs other than README.md. I want my README file to be used for developers to be able to boot up my smart contracts but i want the welcome page of our docs (teller finance) to be better for users. However, there was no way to do this with 'forge doc' as it was hard coded to use README.md . It was also impossible to command 'forge doc' to copy files over and then separately build the book folder with a separate command (that would be nice too but that would have to be a different PR).

Solution

Therefore, I added a config to my foundry.toml file llke so:

[doc]
homepage= "HOME.md"

and I created this PR which changes the builder so that it attempts to read that config value. If it is present, it will use that specified file as the homepage for the docs (the content for README.md in /docs). If not specified, it will fall back to the original code which checked for README in the root and source and then finally falls back upon new String().

@mattsse mattsse requested a review from rkrasiuk April 6, 2023 18:48
Comment on lines +15 to +16
/// Path to user provided welcome markdown (default is Readme.md)
pub homepage: PathBuf,
Copy link
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

Comment on lines +238 to +257

//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(),
}

Copy link
Member

@mattsse mattsse Apr 6, 2023

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

@mattsse mattsse added the Cmd-forge-doc Command: forge doc label Apr 6, 2023
@mattsse
Copy link
Member

mattsse commented Apr 16, 2023

this is basically almost ready,
do you want to proceed with this @ethereumdegen ?

@Evalir Evalir force-pushed the improve-docs-generation branch from 9ee87ad to 2370e8c Compare May 12, 2023 01:36
@Evalir Evalir requested a review from mattsse May 12, 2023 01:44
@mattsse mattsse merged commit cbad9c9 into foundry-rs:master May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cmd-forge-doc Command: forge doc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants