-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add "link tree" element, using directive linktree
#11
Draft
amotl
wants to merge
2
commits into
main
Choose a base branch
from
linktree
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -14,4 +14,4 @@ python: | |
|
||
sphinx: | ||
builder: html | ||
fail_on_warning: true | ||
fail_on_warning: false |
This file contains 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 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,9 @@ | ||
<h3>Classic toctree</h3> | ||
<div class="sidebar-tree"> | ||
{{ sde_linktree_primary }} | ||
</div> | ||
|
||
<h3>Custom linktree</h3> | ||
<div class="sidebar-tree"> | ||
{{ demo_synthetic_linktree }} | ||
</div> |
This file contains 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,10 @@ | ||
{%- extends "!page.html" %} | ||
|
||
{% block content %} | ||
{{ super() }} | ||
|
||
{% if pagename == "linktree" %} | ||
{% include "linktree-demo.html" %} | ||
{% endif %} | ||
|
||
{% endblock %} |
This file contains 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 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 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 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,128 @@ | ||
(linktree-directive)= | ||
|
||
# Link Tree | ||
|
||
|
||
## About | ||
|
||
Similar but different from a Toc Tree. | ||
|
||
```{attention} | ||
This component is a work in progress. Breaking changes should be expected until a | ||
1.0 release, so version pinning is recommended. | ||
``` | ||
|
||
### Problem | ||
|
||
So much work went into the toctree mechanics, it is sad that it is not a reusable | ||
component for building any kinds of navigation structures, and to be able to define | ||
its contents more freely. | ||
|
||
### Solution | ||
|
||
This component implements a programmable toc tree component, the link tree. | ||
|
||
|
||
## Details | ||
|
||
The link tree component builds upon the Sphinx [toc] and [toctree] subsystem. It provides | ||
both a rendered primary navigation within the `sde_linktree_primary` context variable | ||
for use from HTML templates, and a Sphinx directive, `linktree`, for rendering | ||
navigation trees into pages, similar but different from the [toctree directive]. The | ||
user interface mechanics and styles are based on [Furo]'s primary sidebar component. | ||
|
||
|
||
## Customizing | ||
|
||
Link trees can be customized by creating them programmatically, similar to how | ||
the `sde_linktree_primary` context variable is populated with the default Sphinx | ||
toc tree. | ||
|
||
The section hidden behind the dropdown outlines how the "custom linktree" is | ||
defined, which is displayed at the bottom of the page in a rendered variant. | ||
:::{dropdown} Custom linktree example code | ||
|
||
```python | ||
import typing as t | ||
|
||
from sphinx.application import Sphinx | ||
from sphinx_design_elements.lib.linktree import LinkTree | ||
|
||
|
||
def demo_tree(app: Sphinx, context: t.Dict[str, t.Any], docname: str = None) -> LinkTree: | ||
""" | ||
The demo link tree showcases some features what can be done. | ||
|
||
It uses regular page links to documents in the current project, a few | ||
intersphinx references, and a few plain, regular, URL-based links. | ||
""" | ||
linktree = LinkTree.from_context(app=app, context=context) | ||
doc = linktree.api.doc | ||
ref = linktree.api.ref | ||
link = linktree.api.link | ||
|
||
linktree \ | ||
.title("Project-local page links") \ | ||
.add( | ||
doc(name="gridtable"), | ||
doc(name="infocard"), | ||
) | ||
|
||
linktree \ | ||
.title("Intersphinx links") \ | ||
.add( | ||
ref("sd:index"), | ||
ref("sd:badges", label="sphinx{design} badges"), | ||
ref("myst:syntax/images_and_figures", "MyST » Images and figures"), | ||
ref("myst:syntax/referencing", "MyST » Cross references"), | ||
) | ||
|
||
linktree \ | ||
.title("URL links") \ | ||
.add( | ||
link(uri="https://example.com"), | ||
link(uri="https://example.com", label="A link to example.com, using a custom label ⚽."), | ||
) | ||
|
||
return linktree | ||
``` | ||
::: | ||
|
||
```{todo} | ||
- Use the `linktree` directive to define custom link trees. | ||
- Link to other examples of custom link trees. | ||
- Maybe use `:link:` and `:link-type:` directive options of `grid-item-card` directive. | ||
``` | ||
|
||
|
||
## Directive examples | ||
|
||
### Example 1 | ||
|
||
The link tree of the `index` page, using a defined maximum depth, and a custom title. | ||
```{linktree} | ||
:docname: index | ||
:maxdepth: 1 | ||
:title: Custom title | ||
``` | ||
|
||
|
||
## Appendix | ||
|
||
Here, at the bottom of the page, different global template variables are presented, | ||
which contain representations of navigation trees, rendered to HTML. | ||
|
||
- `sde_linktree_primary`: The classic toctree, like it will usually be rendered | ||
into the primary sidebar. | ||
- `demo_synthetic_linktree`: A customized link tree composed of links to project-local | ||
pages, intersphinx links, and URLs, for demonstration purposes. | ||
|
||
```{hint} | ||
The corresponding template, `linktree-demo.html` will exclusively be rendered | ||
here, and not on other pages. | ||
``` | ||
|
||
[Furo]: https://pradyunsg.me/furo/ | ||
[toctree directive]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-toctree | ||
[toc]: https://www.sphinx-doc.org/en/master/development/templating.html#toc | ||
[toctree]: https://www.sphinx-doc.org/en/master/development/templating.html#toctree |
This file contains 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 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 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
Empty file.
Oops, something went wrong.
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.
Needs to be completed by using a custom MyST markup to define the content items of a linktree element.