Skip to content

Commit f8e2bc6

Browse files
committed
Use Furo's navigation component through sphinx-design-elements' linktree
1 parent 0644241 commit f8e2bc6

File tree

13 files changed

+228
-61
lines changed

13 files changed

+228
-61
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGES
55

66
Unreleased
77
----------
8+
- Use Furo's navigation component through ``sphinx-design-elements``'
9+
``linktree``. Thanks, @pradyunsg.
810

911
2024/11/21 0.37.0
1012
-----------------

docs/myst/linktree.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Link Tree
2+
3+
4+
## About
5+
6+
The link tree is a programmable toc tree.
7+
8+
9+
## Example
10+
11+
```{linktree}
12+
```

docs/rst/linktree.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#########
2+
Link Tree
3+
#########
4+
5+
6+
*****
7+
About
8+
*****
9+
10+
The link tree is a programmable toc tree.
11+
12+
13+
*******
14+
Example
15+
*******
16+
17+
.. linktree::

src/crate/theme/ext/__init__.py

Whitespace-only changes.

src/crate/theme/ext/navigation.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- coding: utf-8; -*-
2+
#
3+
# Licensed to Crate (https://crate.io) under one or more contributor
4+
# license agreements. See the NOTICE file distributed with this work for
5+
# additional information regarding copyright ownership. Crate licenses
6+
# this file to you under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License. You may
8+
# obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# However, if you have executed another commercial license agreement
19+
# with Crate these terms will supersede the license and you may use the
20+
# software solely pursuant to the terms of the relevant commercial agreement.
21+
22+
import logging
23+
import typing as t
24+
25+
from sphinx.application import Sphinx
26+
27+
from crate.theme.ext.sidebar import make_primary_tree
28+
from crate.theme.rtd import __version__
29+
from sphinx.builders.html import StandaloneHTMLBuilder
30+
31+
logger = logging.getLogger(__name__)
32+
33+
34+
def html_page_context(
35+
app: Sphinx,
36+
pagename: str,
37+
templatename: str,
38+
context: t.Dict[str, t.Any],
39+
doctree: t.Any,
40+
) -> None:
41+
"""
42+
Sphinx HTML page context provider.
43+
"""
44+
if not isinstance(app.builder, StandaloneHTMLBuilder):
45+
raise Exception(
46+
"Theme is being used with a non-HTML builder. "
47+
"If you're seeing this error, it is a symptom of a mistake in your "
48+
"configuration."
49+
)
50+
51+
# Basic constants
52+
context["theme_version"] = __version__
53+
54+
# Navigation tree component from `sphinx-design-elements`.
55+
try:
56+
primary_tree = make_primary_tree(builder=app.builder, context=context)
57+
context["ng_navigation_tree"] = primary_tree.render()
58+
except Exception as ex:
59+
logger.exception("Unable to compute primary navigation tree")

src/crate/theme/ext/sidebar.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# -*- coding: utf-8; -*-
2+
#
3+
# Licensed to Crate (https://crate.io) under one or more contributor
4+
# license agreements. See the NOTICE file distributed with this work for
5+
# additional information regarding copyright ownership. Crate licenses
6+
# this file to you under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License. You may
8+
# obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# However, if you have executed another commercial license agreement
19+
# with Crate these terms will supersede the license and you may use the
20+
# software solely pursuant to the terms of the relevant commercial agreement.
21+
22+
import typing as t
23+
24+
from sphinx.builders.html import StandaloneHTMLBuilder
25+
26+
from sphinx_design_elements.lib.linktree import LinkTree
27+
28+
29+
def make_primary_tree(builder: StandaloneHTMLBuilder, context: t.Dict[str, t.Any]) -> LinkTree:
30+
project_name = context["project"]
31+
32+
# Create LinkTree component.
33+
linktree = LinkTree.from_context(builder=builder, context=context)
34+
linktree.remove_from_title("CrateDB")
35+
doc = linktree.api.doc
36+
ref = linktree.api.ref
37+
link = linktree.api.link
38+
39+
# Add section about project (self).
40+
project = \
41+
linktree \
42+
.project(docname=project_name, title=project_name)
43+
44+
# .title("Customized TocTree") \
45+
46+
# On specific projects, customize the link tree.
47+
# TODO: Find a way to pull additional navigation hints from project
48+
# markup itself, in order to get rid of this anomaly.
49+
if project_name == "CrateDB Docs Theme":
50+
project.add(
51+
doc(name="admonitions", label="Admonitions"),
52+
doc(name="codesnippets", label="Code snippets"),
53+
doc(name="myst/mermaid", label="Mermaid diagrams, written in Markdown"),
54+
)
55+
56+
# Add project toctree.
57+
project.toctree()
58+
59+
# Add section with links to intersphinx targets.
60+
61+
# CrateDB Database.
62+
linktree \
63+
.title("CrateDB Database") \
64+
.add(
65+
ref(target="crate-reference:index", label="CrateDB Reference"),
66+
ref(target="crate-tutorials:index", label="Install CrateDB"),
67+
ref(target="crate-howtos:index", label="Getting started"),
68+
)
69+
70+
# CrateDB Cloud.
71+
linktree \
72+
.title("CrateDB Cloud") \
73+
.add(
74+
ref("cloud-reference:index"),
75+
ref("cloud-tutorials:index"),
76+
ref("cloud-howtos:index"),
77+
ref("cloud-cli:index"),
78+
)
79+
80+
# CrateDB clients.
81+
linktree \
82+
.title("Clients") \
83+
.add(
84+
ref("crate-admin-ui:index"),
85+
ref("crate-crash:index"),
86+
ref("crate-clients-tools:index"),
87+
ref("crate-jdbc:index"),
88+
ref("crate-npgsql:index"),
89+
ref("crate-dbal:index"),
90+
ref("crate-pdo:index"),
91+
ref("crate-python:index"),
92+
)
93+
94+
# Other links.
95+
linktree \
96+
.title("Miscellaneous") \
97+
.add(
98+
link(uri="https://crate.io/support/", label="Support"),
99+
link(uri="https://community.crate.io/", label="Community"),
100+
link(uri="https://community.crate.io/t/overview-of-cratedb-integration-tutorials/1015", label="Integration tutorials"),
101+
link(uri="https://github.com/crate/cratedb-examples", label="Stacks and examples"),
102+
link(uri="https://github.com/crate/crate-sample-apps", label="Sample applications"),
103+
ref("sql-99:index"),
104+
# ref("crate-docs-theme:index"),
105+
# ref("crate-docs:index"),
106+
)
107+
108+
return linktree

src/crate/theme/rtd/conf/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import os
2222

2323
from crate.theme import rtd as theme
24+
from crate.theme.ext import navigation
2425
from crate.theme.rtd import __version__
25-
from crate.theme.rtd.conf.furo import _html_page_context
2626
from os import environ
2727

2828
source_suffix = ".rst"
@@ -326,7 +326,7 @@ def apply_html_context_custom(app_inited):
326326

327327
# Modern / NG / Furo.
328328
app.require_sphinx("3.0")
329-
app.connect("html-page-context", _html_page_context)
329+
app.connect("html-page-context", navigation.html_page_context)
330330

331331
# Customizations.
332332
app.connect("builder-inited", configure_self_hosted_on_path)
@@ -339,4 +339,3 @@ def apply_html_context_custom(app_inited):
339339
"parallel_write_safe": True,
340340
"version": __version__,
341341
}
342-

src/crate/theme/rtd/conf/furo.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/crate/theme/rtd/crate/components/github_feedback_compact.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<p class="sd-card-text">
5454
<span class="fa fa-code fa-fw"></span>
5555
&nbsp;
56-
<a id="docs-feedback-open-github" class="feedback-compact-link" href="https://{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default('blob') }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ suffix }}?plain=1" rel="noopener" target="_blank" title="View page source on GitHub">View&nbsp;page source</a>
56+
<a id="docs-feedback-open-github" class="feedback-compact-link" href="https://{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default('blob') }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ suffix }}?plain=true" rel="noopener" target="_blank" title="View page source on GitHub">View&nbsp;page source</a>
5757
</p>
5858
{% endif %}
5959

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div role="complementary" class="bs-docs-sidebar hidden-print">
2+
<div class="search-link">
3+
{% if pagename == "search" %}
4+
<a href="search.html" class="btn btn-primary">Search</a>
5+
{% else %}
6+
<a href="{{ pathto('search') }}" class="btn btn-primary">Search</a>
7+
{% endif %}
8+
</div>
9+
</div>

0 commit comments

Comments
 (0)