improving docs generation by adding homepage to config#4702
Merged
mattsse merged 6 commits intofoundry-rs:masterfrom May 12, 2023
Merged
improving docs generation by adding homepage to config#4702mattsse merged 6 commits intofoundry-rs:masterfrom
mattsse merged 6 commits intofoundry-rs:masterfrom
Conversation
mattsse
requested changes
Apr 6, 2023
config/src/doc.rs
Outdated
Comment on lines
+15
to
+16
| /// Path to user provided welcome markdown (default is Readme.md) | ||
| pub homepage: PathBuf, |
Member
There was a problem hiding this comment.
ah so this is expected to be set in the toml file?
I think this should be an Option
doc/src/builder.rs
Outdated
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(), | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
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);
Member
|
this is basically almost ready, |
9ee87ad to
2370e8c
Compare
mattsse
approved these changes
May 12, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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().