Skip to content
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
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

amotl
Copy link
Member

@amotl amotl commented Jul 27, 2023

About

Add a linktree directive, and a corresponding "Link Tree" web element. It is similar but different from a classic Sphinx toc tree. Instead, it is meant to be a programmable toc tree component.

Most importantly, allow users to compose their link trees more freely, using any of the listed link item types, and maybe more.

  • Regular, project-local page links (docnames)
  • Intersphinx references
  • Vanilla URL links

Discuss

Preview

Visually

The visual appearance can be inspected on the RTD preview page.

https://sphinx-design-elements--11.org.readthedocs.build/en/11/linktree.html

Install

The package can be directly installed from the development branch.

pip install --upgrade 'git+https://github.com/panodata/sphinx-design-elements@linktree'

Appearance

image

References

Comment on lines +33 to +65
def demo_tree(builder: Builder, context: t.Dict[str, t.Any], docname: t.Optional[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(builder=builder, 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"),
# rST link syntax.
ref("myst:syntax/images_and_figures", "MyST » Images and figures"),
ref("myst:syntax/referencing", "MyST » Cross references"),
# MyST link syntax.
# ref("myst#syntax/images_and_figures"), # noqa: ERA001
)

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
Copy link
Member Author

@amotl amotl Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how you would currently define a link tree, which will effectively render into a HTML/CSS primary navigation menu using Furo's furo.get_navigation_tree().

In the future, there will be the possibility to define a linktree inline, using markup, just like a toctree. What you can see here is just the first version of a possible Python API for that.

/cc @matkuliak, @msbt, @nomicode

@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Merging #11 (4fad8a8) into main (9c1a880) will decrease coverage by 18.73%.
The diff coverage is 63.19%.

@@             Coverage Diff             @@
##             main      #11       +/-   ##
===========================================
- Coverage   94.44%   75.72%   -18.73%     
===========================================
  Files           6        9        +3     
  Lines         180      449      +269     
===========================================
+ Hits          170      340      +170     
- Misses         10      109       +99     
Flag Coverage Δ
unittests 75.72% <63.19%> (-18.73%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
sphinx_design_elements/linktree.py 51.56% <51.56%> (ø)
sphinx_design_elements/navigation.py 65.00% <65.00%> (ø)
sphinx_design_elements/lib/linktree.py 66.48% <66.48%> (ø)
sphinx_design_elements/extension.py 90.90% <100.00%> (+0.66%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +102 to +107
The link tree of the `index` page, using a defined maximum depth, and a custom title.
```{linktree}
:docname: index
:maxdepth: 1
:title: Custom title
```
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant