-
Notifications
You must be signed in to change notification settings - Fork 339
docs: add the list of component using a directive #1476
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0dadaf4
fix: create the component list automatically
12rambau 9795b9b
fix: read the first comment as documentation
12rambau 964f5be
docs: add disclaimer on .html suffix
12rambau a903bb4
docs: document every component with a simple one liner
12rambau f87e543
fix: use regex to identify comments
12rambau 77e1bfc
update component branch (#15)
12rambau 952f5b8
Merge branch 'main' into component
12rambau 9c3216c
fix: use a directive instead of raw html
12rambau bac6070
Merge branch 'component' of github.com:12rambau/pydata-sphinx-theme i…
12rambau 44b347b
fix: make links externals
12rambau 6fee712
fix: set reference in paragraphs
12rambau 9c9b9df
fix: missing parameter
12rambau ab5e23b
fix: use the stem for the component name
12rambau bb1a607
refactor: remove never used variables
12rambau 02d8b3d
standardize component descriptions
drammock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
"""A directive to generate the list of all the built-in components. | ||
|
||
Read the content of the component folder and generate a list of all the components. | ||
This list will display some informations about the component and a link to the | ||
GitHub file. | ||
""" | ||
import re | ||
from pathlib import Path | ||
from typing import Any, Dict, List | ||
|
||
from docutils import nodes | ||
from sphinx.application import Sphinx | ||
from sphinx.util import logging | ||
from sphinx.util.docutils import SphinxDirective | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
TEMPLATE_LIST = '<ul class="simple">{content}</ul>' | ||
TEMPLATE_LINE = '<li><a href="{url}">{name}</a>: {description}</li>' | ||
|
||
|
||
class ComponentListDirective(SphinxDirective): | ||
"""A directive to generate the list of all the built-in components. | ||
|
||
Read the content of the component folder and generate a list of all the components. | ||
This list will display some informations about the component and a link to the | ||
GitHub file. | ||
""" | ||
|
||
name = "component-list" | ||
has_content = True | ||
required_arguments = 0 | ||
optional_arguments = 0 | ||
final_argument_whitespace = True | ||
|
||
def run(self) -> List[nodes.Node]: | ||
"""Create the list.""" | ||
# get the list of all th jinja templates | ||
# not that to remain compatible with sphinx they are labeled as html files | ||
root = Path(__file__).parents[2] | ||
component_dir = ( | ||
root | ||
/ "src" | ||
/ "pydata_sphinx_theme" | ||
/ "theme" | ||
/ "pydata_sphinx_theme" | ||
/ "components" | ||
) | ||
if not component_dir.is_dir(): | ||
raise FileNotFoundError( | ||
f"Could not find component folder at {component_dir}." | ||
) | ||
components = sorted(component_dir.glob("*.html")) | ||
|
||
# create the list of all the components description using bs4 | ||
# at the moment we use dummy information | ||
docs = [] | ||
pattern = re.compile(r"(?<={#).*?(?=#})", flags=re.DOTALL) | ||
for c in components: | ||
comment = pattern.findall(c.read_text()) | ||
docs.append(comment[0].strip() if comment else "No description available.") | ||
12rambau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# get the urls from the github repo latest branch | ||
github_url = "https://github.com/pydata/pydata-sphinx-theme/blob/main" | ||
urls = [ | ||
f"{github_url}/{component.relative_to(root)}" for component in components | ||
] | ||
|
||
# build the list of all the components | ||
content = "".join( | ||
TEMPLATE_LINE.format(name=component.stem, url=url, description=doc) | ||
for component, url, doc in zip(components, urls, docs) | ||
) | ||
|
||
return [nodes.raw("", TEMPLATE_LIST.format(content=content), format="html")] | ||
|
||
|
||
def setup(app: Sphinx) -> Dict[str, Any]: | ||
"""Add custom configuration to sphinx app. | ||
|
||
Args: | ||
app: the Sphinx application | ||
|
||
Returns: | ||
the 2 parallel parameters set to ``True``. | ||
""" | ||
app.add_directive("component-list", ComponentListDirective) | ||
|
||
return { | ||
"parallel_read_safe": True, | ||
"parallel_write_safe": True, | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/breadcrumbs.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/copyright.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/edit-this-page.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/icon-links.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/indices.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/last-updated.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-icon-links.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{# Display the icons link as inline blocks in the navbar. #} | ||
{%- block icon_links -%} | ||
{%- include "icon-links.html" with context -%} | ||
{%- endblock icon_links %} |
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-logo.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-nav.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/page-toc.html
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
2 changes: 1 addition & 1 deletion
2
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/prev-next.html
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
6 changes: 2 additions & 4 deletions
6
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button-field.html
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
6 changes: 2 additions & 4 deletions
6
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button.html
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
2 changes: 1 addition & 1 deletion
2
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-field.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/sidebar-ethical-ads.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/sidebar-nav-bs.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/sourcelink.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/sphinx-version.html
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
4 changes: 2 additions & 2 deletions
4
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-switcher.html
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
1 change: 1 addition & 0 deletions
1
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{# Display the version of the theme used to build the documentation. #} | ||
<p class="theme-version"> | ||
{% trans theme_version=theme_version|e %}Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> {{ theme_version }}.{% endtrans %} | ||
</p> |
4 changes: 2 additions & 2 deletions
4
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html
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
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.
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.
It'd be fairly easy to express this in terms of nodes rather than pre-written HTML, if you'd like. Doing that would also have the benefit of eg internal/external link tracking, translations, etc.
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 would love to do that but failed to find examples to create a list and combine text and reference nodes. If you have any suggestion I'd be happy to follow them.
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.
Sonething like the below (untested) ought to work?
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 received a weird error:
It is not possible to create a reference from scratch, I'm force to include it into a TextElement ?