Skip to content

Commit d139452

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

File tree

15 files changed

+234
-64
lines changed

15 files changed

+234
-64
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Unreleased
1616
- Add new ``cloud-docs`` documentation project
1717
- Switch to modern responsive 3-column layout theme ``sphinx-basic-ng``.
1818
Thanks, @pradyunsg.
19+
- Use Furo's navigation component through ``sphinx-design-elements``'
20+
``linktree``. Thanks, @pradyunsg.
1921

2022

2123
2023/05/15 0.27.1

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::

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"sphinx-basic-ng==1.0.0b2",
6868
"sphinx-copybutton>=0.3.1,<1",
6969
"sphinx-design<1",
70-
"sphinx-design-elements==0.1.0",
70+
"sphinx-design-elements==0.2.0",
7171
"sphinx-inline-tabs",
7272
"sphinx-sitemap>=2,<3",
7373
"sphinx-subfigure<1",

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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# software solely pursuant to the terms of the relevant commercial agreement.
2121

2222
from crate.theme import rtd as theme
23+
from crate.theme.ext import navigation
2324
from crate.theme.rtd import __version__
24-
from crate.theme.rtd.conf.furo import _html_page_context
2525
from os import environ
2626

2727
source_suffix = ".rst"
@@ -250,9 +250,9 @@ def apply_html_context_custom(app_inited):
250250
except Exception as ex:
251251
print(f"ERROR: Unable to adjust `html_context`. Reason: {ex}")
252252

253-
# Modern / NG / Furo.
253+
# NG: Initialize navigation tree component from `sphinx-design-elements`.
254254
app.require_sphinx("3.0")
255-
app.connect("html-page-context", _html_page_context)
255+
app.connect("html-page-context", navigation.html_page_context)
256256

257257
# Customizations.
258258
app.connect("builder-inited", force_canonical_url)
@@ -265,4 +265,3 @@ def apply_html_context_custom(app_inited):
265265
"parallel_write_safe": True,
266266
"version": __version__,
267267
}
268-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# You can change the `project` value to anything you want because
2626
# `src/crate/theme/rtd/crate/sidebartoc.html` does not have a menu item for
2727
# this project.
28-
project = u"CrateDB Fake Docs"
28+
project = "CrateDB Docs Theme"
2929
html_title = project
3030

3131
url_path = "docs/fake"

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
@@ -51,7 +51,7 @@
5151
<p class="sd-card-text">
5252
<span class="fa fa-code fa-fw"></span>
5353
&nbsp;
54-
<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>
54+
<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>
5555
</p>
5656
</div>
5757
</details>
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>

src/crate/theme/rtd/crate/sections/sidebar-primary.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22
<div class="sidebar-container">
33
<div class="sidebar-sticky">
44

5-
<!-- Section 1 -->
5+
<!-- Google search -->
6+
{% include "components/googlesearch.html" %}
7+
8+
<!-- NG Production -->
69
<div class="sidebar-tree">
710
{{ ng_navigation_tree }}
811
</div>
912

10-
<!-- Section 2 -->
13+
{#
14+
{% if project == 'CrateDB Docs Theme' %}
15+
16+
<!-- Static HTML -->
17+
<span class="sd-text-center sd-fs-5 sd-font-weight-bold sd-text-uppercase sd-text-secondary">
18+
Legacy navigation
19+
</span>
1120
{% include "sidebar.html" %}
21+
22+
{% endif %}
23+
#}
24+
1225
</div>
1326
</div>
1427
</div>

src/crate/theme/rtd/crate/static/css/crateio-rtd.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ div.danger {
174174
}
175175
.bs-docs-sidebar {
176176
padding: 8px 16px;
177-
margin-bottom: 20px;
177+
/* margin-bottom: 20px; */
178178
}
179179

180180
.affix {

src/crate/theme/rtd/crate/static/css/ng/furo.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@
3636
position: unset;
3737
}
3838
}
39+
40+
// Sidebar NG: Adjust margins.
41+
.sidebar-tree {
42+
margin-top: unset;
43+
}

0 commit comments

Comments
 (0)