-
Notifications
You must be signed in to change notification settings - Fork 5
Use Furo's navigation component through sphinx-design-elements' linktree
#405
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
Draft
amotl
wants to merge
4
commits into
main
Choose a base branch
from
amo/basig-ng-navigation
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
4 commits
Select commit
Hold shift + click to select a range
20e8e9b
Use Furo's navigation component through sphinx-design-elements' linktree
amotl 1e8708e
TEMP: Install `sphinx-design-elements` from feature branch
amotl 05e2576
LinkTree: Modernize link tree references
amotl 4bb1a0c
Chore: Satisfy link checker
amotl 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
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,12 @@ | ||
| # Link Tree | ||
|
|
||
|
|
||
| ## About | ||
|
|
||
| The link tree is a programmable toc tree. | ||
|
|
||
|
|
||
| ## Example | ||
|
|
||
| ```{linktree} | ||
| ``` |
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,17 @@ | ||
| ######### | ||
| Link Tree | ||
| ######### | ||
|
|
||
|
|
||
| ***** | ||
| About | ||
| ***** | ||
|
|
||
| The link tree is a programmable toc tree. | ||
|
|
||
|
|
||
| ******* | ||
| Example | ||
| ******* | ||
|
|
||
| .. linktree:: |
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
Empty file.
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,59 @@ | ||
| # -*- coding: utf-8; -*- | ||
| # | ||
| # Licensed to Crate (https://crate.io) under one or more contributor | ||
| # license agreements. See the NOTICE file distributed with this work for | ||
| # additional information regarding copyright ownership. Crate licenses | ||
| # this file to you under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. You may | ||
| # obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
| # However, if you have executed another commercial license agreement | ||
| # with Crate these terms will supersede the license and you may use the | ||
| # software solely pursuant to the terms of the relevant commercial agreement. | ||
|
|
||
| import logging | ||
| import typing as t | ||
|
|
||
| from sphinx.application import Sphinx | ||
|
|
||
| from crate.theme.ext.sidebar import make_primary_tree | ||
| from crate.theme.rtd import __version__ | ||
| from sphinx.builders.html import StandaloneHTMLBuilder | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def html_page_context( | ||
| app: Sphinx, | ||
| pagename: str, | ||
| templatename: str, | ||
| context: t.Dict[str, t.Any], | ||
| doctree: t.Any, | ||
| ) -> None: | ||
| """ | ||
| Sphinx HTML page context provider. | ||
| """ | ||
| if not isinstance(app.builder, StandaloneHTMLBuilder): | ||
| raise Exception( | ||
| "Theme is being used with a non-HTML builder. " | ||
| "If you're seeing this error, it is a symptom of a mistake in your " | ||
| "configuration." | ||
| ) | ||
|
|
||
| # Basic constants | ||
| context["theme_version"] = __version__ | ||
|
|
||
| # Navigation tree component from `sphinx-design-elements`. | ||
| try: | ||
| primary_tree = make_primary_tree(builder=app.builder, context=context) | ||
| context["ng_navigation_tree"] = primary_tree.render() | ||
| except Exception as ex: | ||
| logger.exception("Unable to compute primary navigation tree") |
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,118 @@ | ||
| # -*- coding: utf-8; -*- | ||
| # | ||
| # Licensed to Crate (https://crate.io) under one or more contributor | ||
| # license agreements. See the NOTICE file distributed with this work for | ||
| # additional information regarding copyright ownership. Crate licenses | ||
| # this file to you under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. You may | ||
| # obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
| # However, if you have executed another commercial license agreement | ||
| # with Crate these terms will supersede the license and you may use the | ||
| # software solely pursuant to the terms of the relevant commercial agreement. | ||
|
|
||
| import typing as t | ||
|
|
||
| from sphinx.builders.html import StandaloneHTMLBuilder | ||
|
|
||
| from sphinx_design_elements.lib.linktree import LinkTree | ||
|
|
||
|
|
||
| def make_primary_tree(builder: StandaloneHTMLBuilder, context: t.Dict[str, t.Any]) -> LinkTree: | ||
| """ | ||
| A navigation tree demo defined with Python code. | ||
|
|
||
| It includes two sections: | ||
|
|
||
| - The vanilla toctree of the project at hand.. | ||
| - A linktree composed of Sphinx references or URLs. | ||
| """ | ||
| project_name = context["project"] | ||
|
|
||
| # Create LinkTree component. | ||
| linktree = LinkTree.from_context(builder=builder, context=context) | ||
| linktree.remove_from_title("CrateDB") | ||
| doc = linktree.api.doc | ||
| ref = linktree.api.ref | ||
| link = linktree.api.link | ||
|
|
||
| # Add section about project (self). | ||
| project = \ | ||
| linktree \ | ||
| .project(docname=project_name, title=project_name) | ||
|
|
||
| # .title("Customized TocTree") \ | ||
|
|
||
| # 1. On specific projects, add the vanilla toctree. | ||
| # Here, also customize it for demonstration purposes. | ||
| if project_name == "CrateDB documentation theme": | ||
|
|
||
| # Add vanilla project toctree. | ||
| project.toctree() | ||
|
|
||
| # Add custom navigation items. | ||
| # TODO: Find a way to pull additional navigation hints from project | ||
| # markup itself, in order to get rid of this anomaly. | ||
| project.add( | ||
| doc(name="admonitions", label="Admonitions"), | ||
| doc(name="codesnippets", label="Code snippets"), | ||
| doc(name="myst/mermaid", label="Mermaid diagrams, written in Markdown"), | ||
| ) | ||
|
|
||
| # 2. Add section with links to intersphinx targets. | ||
|
|
||
| # CrateDB Database. | ||
| linktree \ | ||
| .title("CrateDB Database") \ | ||
| .add( | ||
| ref(target="guide:getting-started", label="Getting started"), | ||
| ref(target="guide:index", label="CrateDB Handbook"), | ||
| ref(target="crate-reference:index", label="CrateDB Reference"), | ||
| ref(target="ctk:index", label="CrateDB Toolkit"), | ||
| ) | ||
|
|
||
| # CrateDB Cloud. | ||
| linktree \ | ||
| .title("CrateDB Cloud") \ | ||
| .add( | ||
| ref("cloud:index"), | ||
| ref("cloud-cli:index"), | ||
| ) | ||
|
|
||
| # CrateDB clients. | ||
| linktree \ | ||
| .title("Clients") \ | ||
| .add( | ||
| ref("crate-admin-ui:index"), | ||
| ref("crate-crash:index"), | ||
| ref("guide:connect"), | ||
| ref("connect-java"), | ||
| ref("crate-npgsql:index"), | ||
| ref("crate-dbal:index"), | ||
| ref("crate-pdo:index"), | ||
| ref("crate-python:index"), | ||
| ) | ||
|
|
||
| # Other links. | ||
| linktree \ | ||
| .title("Miscellaneous") \ | ||
| .add( | ||
| link(uri="https://crate.io/support/", label="Support"), | ||
| link(uri="https://community.crate.io/", label="Community"), | ||
| link(uri="https://community.crate.io/t/overview-of-cratedb-integration-tutorials/1015", label="Integration tutorials"), | ||
| link(uri="https://github.com/crate/cratedb-examples", label="Integration examples"), | ||
| link(uri="https://github.com/crate/crate-sample-apps", label="Sample applications"), | ||
| ref("sql-99:index"), | ||
| # ref("crate-docs-theme:index"), | ||
| # ref("crate-docs:index"), | ||
| ) | ||
|
|
||
| return linktree |
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 was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <div role="complementary" class="bs-docs-sidebar hidden-print"> | ||
| <div class="search-link"> | ||
| {% if pagename == "search" %} | ||
| <a href="search.html" class="btn btn-primary">Search</a> | ||
| {% else %} | ||
| <a href="{{ pathto('search') }}" class="btn btn-primary">Search</a> | ||
| {% endif %} | ||
| </div> | ||
| </div> |
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
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.
I've tried to assemble this yesterday to see what's missing....
Uh oh!
There was an error while loading. Please reload this page.
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.
... and encountered an "unexpected" exception on CI:
-- https://github.com/crate/crate-docs-theme/actions/runs/20082409491/job/57612387226?pr=405#step:7:492
Uh oh!
There was an error while loading. Please reload this page.
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.
Well, this doesn't mean much, because it's all just a draft, originally conceived more than two years ago. However, it highlights that software parts currently do NOT fit together well, so the package needs some more love. A little import error per se is nothing to worry about, I am sure there might be the one or the other different obstacle along the way to general availability.
Uh oh!
There was an error while loading. Please reload this page.
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 suggested a fix for the build issue. But yeah, looking at the code and the amount of remaining todos, it seems there still is quite a bit of work left? While this is likely a better way, it's probably a bit too involved for me at this moment.