-
Notifications
You must be signed in to change notification settings - Fork 152
new: Add generated documentation website #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
a28e46a to
9bb4769
Compare
45fb447 to
c4da9d4
Compare
baf5659 to
8f1cd4f
Compare
|
|
||
| return self._handle_list_items(list_items, parsed) | ||
|
|
||
| def build_parser( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split this into multiple functions so we can extract the generated usage text for use in the docs
linodecli/baked/parsing.py
Outdated
| relevant_lines = None | ||
|
|
||
| for i, line in enumerate(target_lines): | ||
| def __simplify(sentence: str) -> Optional[str]: | ||
| # Edge case for descriptions starting with a note | ||
| if line.lower().startswith("__note__"): | ||
| continue | ||
| if sentence.lower().startswith("__note__"): | ||
| return None | ||
|
|
||
| sentence = strip_techdocs_prefixes(sentence) | ||
|
|
||
| relevant_lines = target_lines[i:] | ||
| break | ||
| # Check that the sentence still has content after stripping prefixes | ||
| if len(sentence) < 2: | ||
| return None | ||
|
|
||
| if relevant_lines is None: | ||
| return sentence + "." | ||
|
|
||
| # Find the first relevant sentence | ||
| result = next( | ||
| simplified | ||
| for simplified in iter( | ||
| __simplify(sentence) | ||
| for sentence in REGEX_SENTENCE_DELIMITER.split(description) | ||
| ) | ||
| if simplified is not None | ||
| ) | ||
|
|
||
| if result is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overhauled the logic in this function to account for some new cases I ran into
| result_no_links, links = extract_markdown_links(result) | ||
|
|
||
| if len(links) > 0: | ||
| description += f" See: {'; '.join(links)}" | ||
| result_no_links += f" See: {'; '.join(links)}" | ||
|
|
||
| return unescape(markdown_to_rich_markup(description)), unescape(description) | ||
| return unescape(markdown_to_rich_markup(result_no_links)), unescape(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was updated to store one mostly unchanged version and one fully formatted version of the description, giving us more flexibility in the docs
| self.load_baked() | ||
|
|
||
| def bake(self, spec): | ||
| def bake(self, spec: Dict[str, Any], file: Optional[IO[bytes]] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes allow us to construct a mock CLI from a custom spec in unit tests
| T = TypeVar("T") | ||
|
|
||
|
|
||
| def sorted_actions_smart( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't live with the rest of the util functions because it can also be used in the command --help pages
📝 Description
This pull request implements a new generated documentation site that is automatically pushed to GitHub Pages.
The below preview URLs can be preview the documentation site in your browser:
Rendering
This PR uses Sphinx with the Read the Docs theme to render documentation. The Sphinx configuration and all relevant static files are stored under the
docsdirectory.Command Documentation Generation
Due to the complexity and abundance of CLI commands, the logic to generate documentation pages for CLI commands is located in the
linodecli/documentationdirectory.The
linodecli/documentation/templatesdirectory contains various Jinja2 templates which are dynamically rendered using the structures defined inlinodecli/documentation/template_data.py.CLI documentation pages are rendered to a user-defined directory when
linode-cli generate-docsis called. This is an indirect dependency of themake generate-docstarget, which will automatically render the command documentation into thedocs/_generateddirectory before executing any Sphinx commands.Publishing
To automatically publish the documentation to a publicly available URL, this PR adds a new documentation.yml GitHub Actions workflow file.
This workflow has three jobs:
Build the documentation and upload it as an artifact
Pull down the built docs from the first step and commit them to the
_documentationbranchmain,dev)_documentationbranch automatically be created if it does not already exist.Pull down the built docs from the first step and upload them as a release asset.
The Documentation Branch
This PR uses a dedicated documentation branch because it allows us to make multiple versions of the documentation available at at time. Additionally, this allows us to manually rebase any sensitive/unwanted documentation details.
This branch stores all relevant versions as subdirectories, with the
latestdirectory andindex.htmlfiles being updated on-demand by job #2 (mentioned above).✔️ Testing
The following test steps assume you have pulled down this PR locally and run
make install.Unit Testing
Documentation Rendering
generate-docstarget:Ensure the documentation generates successfully.
Open the documentation index in your browser:
Publishing
new/doc-generationbranch on your fork containing the changes from this PR:BuildandCommit to Pages Branchjobs under theBuild Documentationworkflow run successfully under your fork.Deploy from a branch, the target branch to the_documentationbranch, and the path to/ (root).MYGHUSERNAME.github.io/linode-cli/new/doc-generation.new/doc-generationbranch.new/doc-generationbranch with the formatvX.X.X.MYGHUSERNAME.github.io/linode-cli/latest.📷 Preview
Configuration Page