Skip to content

Commit 9e2bc2f

Browse files
authored
NEH: Icon links, latest PST, more source providers, and bug fixes (#691)
1 parent 30d0c2d commit 9e2bc2f

31 files changed

Lines changed: 667 additions & 243 deletions

docs/_static/ebp-logo.png

1.47 KB
Loading

docs/components/icon-links.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Icon links and badges
2+
3+
You can add a collection of icon links and badges to your primary sidebar.
4+
For example, to include links to your GitHub repository or a [shields.io badge](https://shields.io).
5+
See the {external:ref}`PyData Icon Links documentation <icon-links>` for how to configure this.

docs/components/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Components are specific UI elements that you can control with configuration.
44

55
```{toctree}
66
logo
7+
icon-links
78
download
89
source-files
910
custom-css

docs/components/source-files.md

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,123 @@
33

44
There are a collection of buttons that you can use to link back to your source
55
repository. This lets users browse the repository, or take actions like suggest
6-
an edit or open an issue. In each case, they require the following configuration
7-
to exist:
6+
an edit or open an issue.
7+
8+
(source-buttons:repository)=
9+
## Set your source repository
10+
11+
You need to define a **source repository** for this functionality to work.
12+
This is the online space where your code / documentation is hosted.
13+
To
14+
In each case, they require the following configuration to exist:
815

916
```python
1017
html_theme_options = {
1118
...
12-
"repository_url": "https://github.com/{your-docs-url}",
19+
"repository_url": "https://{your-provider}/{org}/{repo}",
1320
...
1421
}
1522
```
1623

17-
(source-files:repository)=
18-
## Add a link to your repository
24+
Three providers are supported:
1925

20-
To add a link to your repository, add the following configuration:
26+
- **GitHub**: For example, `https://github.com/executablebooks/sphinx-book-theme`.
27+
This includes custom URLs for self-hosted GitHub.
28+
- **GitLab**: For example, `https://gitlab.com/gitlab-org/gitlab`.
29+
This includes custom URLs for self-hosted GitLab.
30+
- **BitBucket**: For example, `https://opensource.ncsa.illinois.edu/bitbucket/scm/u3d/3dutilities`.
31+
32+
In each case, we **assume the final two URL items are the `org/repo` pair**.
33+
34+
### Manually specify the provider
35+
36+
If your provider URL is more complex (e.g., if you're self-hosting your provider), you can manually specify the provider with the following configuration:
2137

2238
```python
2339
html_theme_options = {
2440
...
25-
"repository_url": "https://github.com/{your-docs-url}",
26-
"use_repository_button": True,
41+
"repository_provider": "gitlab" # or "github", "bitbucket",
42+
"repository_url": "selfhostedgh.mycompany.org/user/repo",
2743
...
2844
}
2945
```
3046

31-
## Add a button to open issues
47+
Once this is provided, you may add source buttons by following the following sections.
3248

33-
To add a button to open an issue about the current page, use the following
34-
configuration:
49+
(source-buttons:source)=
50+
## Add a button to the page source
51+
52+
Show the raw source of the page on the provider you've proivded.
53+
To add a button to the page source, first [configure your source repository](source-buttons:repository) and then add:
3554

3655
```python
3756
html_theme_options = {
3857
...
39-
"repository_url": "https://github.com/{your-docs-url}",
40-
"use_issues_button": True,
58+
"use_source_button": True,
59+
...
60+
}
61+
```
62+
63+
Then configure the **repository branch** to use for your source.
64+
By default it is `main`, but if you'd like to change this, use the following configuration:
65+
66+
```python
67+
html_theme_options = {
68+
...
69+
"repository_branch": "{your-branch}",
70+
...
71+
}
72+
```
73+
74+
Finally, **configure the relative path to your documentation**.
75+
By default, this is the root of the repository, but if your documentation is hosted in a sub-folder, use the following configuration:
76+
77+
```python
78+
html_theme_options = {
79+
...
80+
"path_to_docs": "{path-relative-to-site-root}",
4181
...
4282
}
4383
```
4484

4585
## Add a button to suggest edits
4686

47-
You can add a button to each page that will allow users to edit the page text
48-
directly and submit a pull request to update the documentation. To include this
49-
button, use the following configuration:
87+
Allow users to edit the page text directly on the provider and submit a pull request to update the documentation.
88+
To add a button to edit the page, first [configure your source repository](source-buttons:repository) and then add:
5089

5190
```python
5291
html_theme_options = {
5392
...
54-
"repository_url": "https://github.com/{your-docs-url}",
5593
"use_edit_page_button": True,
5694
...
5795
}
5896
```
5997

60-
By default, the edit button will point to the `master` branch, but if you'd like
61-
to change this, use the following configuration:
98+
Then follow the [branch and relative path instructions in the source file section](source-buttons:source).
99+
100+
101+
(source-files:repository)=
102+
## Add a link to your repository
103+
104+
To add a link to your repository, add the following configuration:
62105

63106
```python
64107
html_theme_options = {
65108
...
66-
"repository_branch": "{your-branch}",
109+
"use_repository_button": True,
67110
...
68111
}
69112
```
70113

71-
By default, the edit button will point to the root of the repository. If your
72-
documentation is hosted in a sub-folder, use the following configuration:
114+
## Add a button to open issues
115+
116+
To add a button to open an issue about the current page, use the following
117+
configuration:
73118

74119
```python
75120
html_theme_options = {
76121
...
77-
"path_to_docs": "{path-relative-to-site-root}",
122+
"use_issues_button": True,
78123
...
79124
}
80125
```

docs/conf.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
html_theme_options = {
109109
"path_to_docs": "docs",
110110
"repository_url": "https://github.com/executablebooks/sphinx-book-theme",
111-
# "repository_branch": "gh-pages", # For testing
111+
"repository_branch": "master",
112112
"launch_buttons": {
113113
"binderhub_url": "https://mybinder.org",
114114
"colab_url": "https://colab.research.google.com/",
@@ -118,8 +118,9 @@
118118
# "jupyterhub_url": "https://datahub.berkeley.edu", # For testing
119119
},
120120
"use_edit_page_button": True,
121+
"use_source_button": True,
121122
"use_issues_button": True,
122-
"use_repository_button": True,
123+
# "use_repository_button": True,
123124
"use_download_button": True,
124125
"use_sidenotes": True,
125126
"show_toc_level": 2,
@@ -131,6 +132,25 @@
131132
"image_dark": "_static/logo-wide-dark.svg",
132133
# "text": html_title, # Uncomment to try text with logo
133134
},
135+
"icon_links": [
136+
{
137+
"name": "Executable Books",
138+
"url": "https://executablebooks.org/",
139+
"icon": "_static/ebp-logo.png",
140+
"type": "local",
141+
},
142+
{
143+
"name": "GitHub",
144+
"url": "https://github.com/executablebooks/sphinx-book-theme",
145+
"icon": "fa-brands fa-github",
146+
},
147+
{
148+
"name": "PyPI",
149+
"url": "https://pypi.org/project/sphinx-book-theme/",
150+
"icon": "https://img.shields.io/pypi/dw/sphinx-book-theme",
151+
"type": "url",
152+
},
153+
],
134154
# For testing
135155
# "use_fullscreen_button": False,
136156
# "home_page_in_toc": True,

docs/content/launch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To add Google Colab links to your page, add the following configuration:
6262
html_theme_options = {
6363
...
6464
"launch_buttons": {
65-
"colab_url": "https://{your-colab-url}"
65+
"colab_url": "https://colab.research.google.com"
6666
},
6767
...
6868
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ readme = "README.md"
2323
requires-python = ">=3.7"
2424
dependencies = [
2525
"sphinx>=4,<7",
26-
"pydata-sphinx-theme>=0.13.0rc4",
26+
"pydata-sphinx-theme>=0.13.0rc5",
2727
]
2828

2929
license = { file = "LICENSE" }

src/sphinx_book_theme/__init__.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
from sphinx.application import Sphinx
1010
from sphinx.locale import get_translation
1111
from sphinx.util import logging
12+
from pydata_sphinx_theme import _get_theme_options
1213

1314
from .nodes import SideNoteNode
14-
from .header_buttons import prep_header_buttons, add_header_buttons, update_sourcename
15+
from .header_buttons import (
16+
prep_header_buttons,
17+
add_header_buttons,
18+
update_sourcename,
19+
update_context_with_repository_info,
20+
)
1521
from .header_buttons.launch import add_launch_buttons
22+
from .header_buttons.source import add_source_buttons
1623
from ._transforms import HandleFootnoteTransform
1724

1825
__version__ = "1.0.0rc2"
@@ -60,7 +67,7 @@ def add_metadata_to_page(app, pagename, templatename, context, doctree):
6067
context["translate"] = translation
6168

6269
# If search text hasn't been manually specified, use a shorter one here
63-
theme_options = app.builder.theme_options or {}
70+
theme_options = _get_theme_options(app)
6471
if "search_bar_text" not in theme_options:
6572
context["theme_search_bar_text"] = translation("Search") + "..."
6673

@@ -89,7 +96,7 @@ def hash_assets_for_files(assets: list, theme_static: Path, context):
8996
asset_sphinx_link = f"_static/{asset}"
9097
asset_source_path = theme_static / asset
9198
if not asset_source_path.exists():
92-
SPHINX_LOGGER.warn(
99+
SPHINX_LOGGER.warning(
93100
f"Asset {asset_source_path} does not exist, not linking."
94101
)
95102
# Find this asset in context, and update it to include the digest
@@ -115,7 +122,7 @@ def hash_html_assets(app, pagename, templatename, context, doctree):
115122

116123
def update_mode_thebe_config(app):
117124
"""Update thebe configuration with SBT-specific values"""
118-
theme_options = app.builder.theme_options
125+
theme_options = _get_theme_options(app)
119126
if theme_options.get("launch_buttons", {}).get("thebe") is True:
120127
# In case somebody specifies they want thebe in a launch button
121128
# but has not activated the sphinx_thebe extension.
@@ -154,7 +161,7 @@ def check_deprecation_keys(app):
154161

155162
deprecated_config_list = ["single_page"]
156163
for key in deprecated_config_list:
157-
if key in app.builder.theme_options:
164+
if key in _get_theme_options(app):
158165
SPHINX_LOGGER.warning(
159166
f"'{key}' was deprecated from version 0.3.4 onwards. See the CHANGELOG for more information: https://github.com/executablebooks/sphinx-book-theme/blob/master/CHANGELOG.md" # noqa: E501
160167
f"[{DEFAULT_LOG_TYPE}]",
@@ -181,14 +188,14 @@ def run(self):
181188
return nodes
182189

183190

184-
def update_general_config(app, config):
191+
def update_general_config(app):
185192
theme_dir = get_html_theme_path()
186193
# Update templates for sidebar. Needed for jupyter-book builds as jb
187194
# uses an instance of Sphinx class from sphinx.application to build the app.
188195
# The __init__ function of which calls self.config.init_values() just
189196
# before emitting `config-inited` event. The init_values function overwrites
190197
# templates_path variable.
191-
config.templates_path.append(os.path.join(theme_dir, "components"))
198+
app.config.templates_path.append(os.path.join(theme_dir, "components"))
192199

193200

194201
def update_templates(app, pagename, templatename, context, doctree):
@@ -227,7 +234,8 @@ def setup(app: Sphinx):
227234
app.connect("builder-inited", update_mode_thebe_config)
228235
app.connect("builder-inited", check_deprecation_keys)
229236
app.connect("builder-inited", update_sourcename)
230-
app.connect("config-inited", update_general_config)
237+
app.connect("builder-inited", update_context_with_repository_info)
238+
app.connect("builder-inited", update_general_config)
231239
app.connect("html-page-context", add_metadata_to_page)
232240
app.connect("html-page-context", hash_html_assets)
233241
app.connect("html-page-context", update_templates)
@@ -237,8 +245,9 @@ def setup(app: Sphinx):
237245

238246
# Header buttons
239247
app.connect("html-page-context", prep_header_buttons)
240-
app.connect("html-page-context", add_launch_buttons)
241-
# Bump priority by 1 so that it runs after the pydata theme sets up the edit URL.
248+
# Bump priority so that it runs after the pydata theme sets up the edit URL func.
249+
app.connect("html-page-context", add_launch_buttons, priority=501)
250+
app.connect("html-page-context", add_source_buttons, priority=501)
242251
app.connect("html-page-context", add_header_buttons, priority=501)
243252

244253
# Directives

src/sphinx_book_theme/_transforms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any
33
from docutils import nodes as docutil_nodes
44
from sphinx import addnodes as sphinx_nodes
5+
from pydata_sphinx_theme import _get_theme_options
56
from .nodes import SideNoteNode
67

78

@@ -12,7 +13,7 @@ class HandleFootnoteTransform(SphinxPostTransform):
1213
formats = ("html",)
1314

1415
def run(self, **kwargs: Any) -> None:
15-
theme_options = self.app.builder.theme_options
16+
theme_options = _get_theme_options(self.app)
1617
if theme_options.get("use_sidenotes", False) is False:
1718
return None
1819
# Cycle through footnote references, and move their content next to the
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Icon links design for the primary sidebar, where it defaults in this theme.
3+
*/
4+
.bd-sidebar-primary {
5+
.navbar-icon-links {
6+
column-gap: 0.5rem;
7+
8+
.nav-link {
9+
// There are few kinds of elements that can be icon links and each is different
10+
i,
11+
span {
12+
font-size: 1.2rem;
13+
}
14+
15+
// Images usually fill more vertical space so we make them a bit smaller
16+
img {
17+
font-size: 0.8rem;
18+
}
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)