Skip to content

Commit e99dea1

Browse files
choldgrafpre-commit-ci[bot]AakashGfude
authored
MAINT: Remove duplication with pydata-sphinx-theme (#640)
* Removing cruft for pydata theme * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixing tox * typo * bd article p-r-2 * footer and secondary sidebar * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * had to add _footer-content.scss, as pydata does not have any style * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * had to add _footer-content.scss, as pydata does not have any style * hide the header btn on wide screens * bd-main flex-grow is not necessary in sbt * removing unnecessary style/mixins and adding some * adding noqa * removing unnecessary class and editing sidebar secondary option * removing sidebar secondary buttons * hiding source link * pydata version * span.sidenote and span.marginnote z-index * citation style * google link * dependency changes * file changes * no print for sidebar secondary * adding sphinx 4,5 in tox and secondary sidebar now won't show up when no headings present * deprecating single_page, extra navbar, navbar_footer_text html options * execution_show_tb to nb_execution_show_tb * table style * urlib.parse warning and custom-footer link removal * images with fixed height/width * search page style and fading of primary sidebar * code block margin and show-inpage-toc * margin content pushes code cells down * output tag style * announcemnet color * search page style * extension added for syntax highlighting * Update src/sphinx_book_theme/assets/styles/components/_search.scss Co-authored-by: Chris Holdgraf <[email protected]> * ipython version * checking if ipython version is the issue * removing pygments_lexer metadata in test file * jupyter logo * logo img link * adding deprecation for single page * adding deprecation for single page * removing border bottom for margins * margin and sidebar styles * font sizes for primary sidebar * relaxing lighthouse score * scrollbar mixin and animation * responsive css and nav scroll attempt * Remove buttons and responsive behavior fixes * Cleaning up margin behavior * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Changelog error * Fix tests * More test fixes * Move install to pyproject * Pinning to latest release of pydata theme * flex-basis primary-sidebar * search text * menu dropdown css * alignment of buttons * sidebar and margin fixes * Tweaking two items Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: AakashGC <[email protected]>
1 parent 0c40452 commit e99dea1

File tree

73 files changed

+815
-1638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+815
-1638
lines changed

.github/workflows/lighthouserc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"assert": {
1111
"assertions": {
12-
"categories:performance": ["error", { "minScore": 0.85 }],
13-
"categories:accessibility": ["error", { "minScore": 0.85 }],
14-
"categories:best-practices": ["error", { "minScore": 0.85 }]
12+
"categories:performance": ["error", { "minScore": 0.84 }],
13+
"categories:accessibility": ["error", { "minScore": 0.84 }],
14+
"categories:best-practices": ["error", { "minScore": 0.84 }]
1515
}
1616
}
1717
}

docs/conf.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
# so a file named "default.css" will overwrite the builtin "default.css".
9898
html_static_path = ["_static"]
9999
html_css_files = ["custom.css"]
100-
jupyter_execute_notebooks = "cache"
100+
nb_execution_mode = "cache"
101101
thebe_config = {
102102
"repository_url": "https://github.com/binder-examples/jupyter-stacks-datascience",
103103
"repository_branch": "master",
@@ -129,9 +129,7 @@
129129
# For testing
130130
# "use_fullscreen_button": False,
131131
# "home_page_in_toc": True,
132-
# "single_page": True,
133132
# "extra_footer": "<a href='https://google.com'>Test</a>", # DEPRECATED KEY
134-
# "extra_navbar": "<a href='https://google.com'>Test</a>",
135133
# "show_navbar_depth": 2,
136134
}
137135

@@ -142,12 +140,12 @@
142140
fontawesome_included = True
143141
post_auto_image = 1
144142
post_auto_excerpt = 2
145-
execution_show_tb = "READTHEDOCS" in os.environ
143+
nb_execution_show_tb = "READTHEDOCS" in os.environ
146144
bibtex_bibfiles = ["references.bib"]
147145
# To test that style looks good with common bibtex config
148146
bibtex_reference_style = "author_year"
149147
bibtex_default_style = "plain"
150-
148+
numpydoc_show_class_members = False # for automodule:: urllib.parse stub file issue
151149
linkcheck_ignore = [
152150
"http://someurl/release", # This is a fake link
153151
"https://doi.org", # These don't resolve properly and cause SSL issues

docs/customize/footer-content.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Customize the content footer
2+
3+
There is a content footer that spans the width of the page, and is visibile when you scroll to the bottom of the content.
4+
5+
By default, the content footer has the following items:
6+
7+
- `author.html`: Display the author of the page, if present.
8+
- `copyright.html`: Display copyright information about the website.
9+
- `last-updated.html`: Display the latest date that the website was updated.
10+
- `extra-footer.html`: A placeholder for arbitrary HTML you may add (see [](content-footer:extra-footer)).
11+
12+
(content-footer:extra-footer)=
13+
## Add extra HTML to your content footer
14+
15+
You may add custom HTML to the content footer via `conf.py`.
16+
This is a shortcut in case you wish to avoid defining your own HTML template.
17+
18+
To do so, use the `extra_footer` configuration and provide any HTML that you wish.
19+
For example:
20+
21+
```python
22+
html_theme_options = {
23+
...
24+
"extra_footer": "<div>hi there!</div>",
25+
}
26+
```

docs/customize/index.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ The following options are available via `html_theme_options`
1212
* - Key
1313
- Type
1414
- Description
15-
* - `single_page`
16-
- bool
17-
- Remove the left sidebar and treat the site as a single page. See [](customize:single-page).
1815
* - `path_to_docs`
1916
- string
2017
- Path to the documentation, relative to the repository root (e.g. `docs/`). See [](customize:source-files).
@@ -48,9 +45,6 @@ The following options are available via `html_theme_options`
4845
* - `show_navbar_depth`
4946
- int
5047
- Show children in the navigation bar down to the depth listed here. See [](sidebar:navbar-depth).
51-
* - `extra_navbar`
52-
- str
53-
- Extra HTML to add below the sidebar footer. See [](custom-footer).
5448
* - `extra_footer`
5549
- str
5650
- Extra HTML to add in the footer of each page.
@@ -66,10 +60,10 @@ The following sections describe a few ways to customize the theme in more depth.
6660
```{toctree}
6761
sidebar-primary.md
6862
sidebar-secondary.md
63+
footer-content.md
6964
announcements.md
7065
header.md
7166
download.md
7267
source-files.md
7368
custom-css.md
74-
single-page.md
7569
```

docs/customize/sidebar-primary.md

-16
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ By default, this theme comes with these three theme-specific sidebar elements en
3636
- `sidebar-logo.html`: Displays the logo and site title.
3737
- `search-field.html`: A bootstrap-based search bar (from the [PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/))
3838
- `sbt-sidebar-nav.html`: A bootstrap-based navigation menu for your book.
39-
- `sbt-sidebar-footer`: A [configurable](custom-footer) snippet of HTML to add to the sidebar (by default it is placed at the bottom).
40-
41-
(custom-footer)=
42-
## Customize the sidebar footer
43-
44-
You may choose your own HTML to include in the footer of your sidebar (or set it to be empty). To do so, set the following option in `conf.py`:
45-
46-
```python
47-
html_theme_options = {
48-
...
49-
"extra_navbar": "<p>Your HTML</p>",
50-
...
51-
}
52-
```
53-
54-
This text will be placed at the bottom of the sidebar by default.
5539

5640

5741
## Add a header to your Table of Contents

docs/customize/single-page.md

-14
This file was deleted.

docs/reference/special-theme-elements.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ how does it look?
218218
219219
Markdown cell with images in sidebar
220220
221-
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png" style="max-width:200px" />
221+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png" />
222222
223223
````
224224
+++

pyproject.toml

+7-4
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,<6",
26-
"pydata-sphinx-theme~=0.10.1",
26+
"pydata-sphinx-theme~=0.12.0",
2727
"pyyaml",
2828
]
2929

@@ -53,11 +53,11 @@ doc = [
5353
"numpy",
5454
"matplotlib",
5555
"numpydoc",
56-
"myst-nb~=0.13.2",
56+
"myst-nb~=0.16.0",
5757
"nbclient",
5858
"pandas",
5959
"plotly",
60-
"sphinx~=4.0",
60+
"sphinx>=4.0,<6",
6161
"sphinx-design",
6262
"sphinx-examples",
6363
"sphinx-copybutton",
@@ -67,11 +67,14 @@ doc = [
6767
"sphinxcontrib-bibtex~=2.2",
6868
"sphinxcontrib-youtube",
6969
"sphinxext-opengraph",
70+
# 8.7.0 broke the `ipython3` lexer in Sphinx so we want to avoid it
71+
# remove this when 8.7.1 is released (and see below for another instance)
72+
"ipython!=8.7.0",
7073
]
7174
test = [
7275
"beautifulsoup4>=4.6.1,<5",
7376
"coverage",
74-
"myst-nb~=0.13.2",
77+
"myst-nb~=0.16.0",
7578
"pytest~=7.1",
7679
"pytest-cov>=3,<5",
7780
"pytest-regressions>=2.0.1,<2.5.0",

src/sphinx_book_theme/__init__.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""sphinx-book-theme version"""
2020

2121
SPHINX_LOGGER = logging.getLogger(__name__)
22+
DEFAULT_LOG_TYPE = "sphinxbooktheme"
2223
MESSAGE_CATALOG_NAME = "booktheme"
2324

2425

@@ -59,7 +60,7 @@ def add_metadata_to_page(app, pagename, templatename, context, doctree):
5960
context["translate"] = translation
6061
# this is set in the html_theme
6162
context["theme_search_bar_text"] = translation(
62-
context.get("theme_search_bar_text", "Search the docs ...")
63+
context.get("theme_search_bar_text", "Search...")
6364
)
6465

6566

@@ -151,6 +152,19 @@ def update_mode_thebe_config(app):
151152
app.config.html_context["default_mode"] = "light"
152153

153154

155+
def check_deprecation_keys(app):
156+
"""Warns about the deprecated keys."""
157+
158+
deprecated_config_list = ["single_page"]
159+
for key in deprecated_config_list:
160+
if key in app.env.config.html_theme_options:
161+
SPHINX_LOGGER.warning(
162+
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
163+
f"[{DEFAULT_LOG_TYPE}]",
164+
type=DEFAULT_LOG_TYPE,
165+
)
166+
167+
154168
class Margin(Sidebar):
155169
"""Goes in the margin to the right of the page."""
156170

@@ -180,6 +194,28 @@ def update_general_config(app, config):
180194
config.templates_path.append(os.path.join(theme_dir, "components"))
181195

182196

197+
def update_templates(app, pagename, templatename, context, doctree):
198+
"""Update template names and assets for page build.
199+
200+
This is a copy of what the pydata theme does here to include a new section
201+
- https://github.com/pydata/pydata-sphinx-theme/blob/0a4894fab49befc59eb497811949a1d0ede626eb/src/pydata_sphinx_theme/__init__.py#L173 # noqa: E501
202+
"""
203+
# Allow for more flexibility in template names
204+
template_sections = ["theme_footer_content_items"]
205+
for section in template_sections:
206+
if context.get(section):
207+
# Break apart `,` separated strings so we can use , in the defaults
208+
if isinstance(context.get(section), str):
209+
context[section] = [
210+
ii.strip() for ii in context.get(section).split(",")
211+
]
212+
213+
# Add `.html` to templates with no suffix
214+
for ii, template in enumerate(context.get(section)):
215+
if not os.path.splitext(template)[1]:
216+
context[section][ii] = template + ".html"
217+
218+
183219
def setup(app: Sphinx):
184220
# Register theme
185221
theme_dir = get_html_theme_path()
@@ -192,9 +228,11 @@ def setup(app: Sphinx):
192228

193229
# Events
194230
app.connect("builder-inited", update_mode_thebe_config)
231+
app.connect("builder-inited", check_deprecation_keys)
195232
app.connect("config-inited", update_general_config)
196233
app.connect("html-page-context", add_metadata_to_page)
197234
app.connect("html-page-context", hash_html_assets)
235+
app.connect("html-page-context", update_templates)
198236

199237
# Nodes
200238
SideNoteNode.add_node(app)

src/sphinx_book_theme/_transforms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from docutils import nodes as docutil_nodes
44
from sphinx import addnodes as sphinx_nodes
55
from .nodes import SideNoteNode
6-
import copy
76

87

98
class HandleFootnoteTransform(SphinxPostTransform):
@@ -64,7 +63,7 @@ def run(self, **kwargs: Any) -> None:
6463
# so it works w/ margin. Only show one or another depending on
6564
# screen width.
6665
node_parent = ref_node.parent
67-
para_dup = copy.deepcopy(para)
66+
para_dup = para.deepcopy()
6867
# looping to check parent node
6968
while not isinstance(
7069
node_parent, (docutil_nodes.section, sphinx_nodes.document)

src/sphinx_book_theme/assets/scripts/index.js

+3-42
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ var initTocHide = () => {
9797

9898
// Hide the TOC if any margin content is displayed on the screen
9999
if (onScreenItems.length > 0) {
100-
$("div.bd-sidebar-secondary").removeClass("show");
100+
$("div.bd-sidebar-secondary").addClass("hide");
101101
} else {
102-
$("div.bd-sidebar-secondary").addClass("show");
102+
$("div.bd-sidebar-secondary").removeClass("hide");
103103
}
104104
};
105105
let manageScrolledClassOnBody = (entries, observer) => {
@@ -159,50 +159,13 @@ var initThebeSBT = () => {
159159
initThebe();
160160
};
161161

162-
/**
163-
* Use Bootstrap helper function to enable tooltips.
164-
*/
165-
var initTooltips = () => {
166-
$(document).ready(function () {
167-
$('[data-toggle="tooltip"]').tooltip({
168-
trigger: "hover",
169-
delay: { show: 500, hide: 100 },
170-
});
171-
});
172-
};
173-
174-
/**
175-
* MutationObserver to move the ReadTheDocs button
176-
*/
177-
function initRTDObserver() {
178-
const mutatedCallback = (mutationList, observer) => {
179-
mutationList.forEach((mutation) => {
180-
// Check whether the mutation is for RTD, which will have a specific structure
181-
if (mutation.addedNodes.length === 0) {
182-
return;
183-
}
184-
if (mutation.addedNodes[0].data === undefined) {
185-
return;
186-
}
187-
if (mutation.addedNodes[0].data.search("Inserted RTD Footer") != -1) {
188-
mutation.addedNodes.forEach((node) => {
189-
document.getElementById("rtd-footer-container").append(node);
190-
});
191-
}
192-
});
193-
};
194-
195-
const observer = new MutationObserver(mutatedCallback);
196-
const config = { childList: true };
197-
observer.observe(document.body, config);
198-
}
199-
200162
/**
201163
* Add no print class to certain DOM elements
202164
*/
203165

204166
function addNoPrint() {
205167
$("div.bd-sidebar-primary").addClass("noprint");
168+
$("div.bd-sidebar-secondary").addClass("noprint");
206169
$("div.bd-header-article").addClass("noprint");
207170
$("div.bd-header-announcement").addClass("noprint");
208171
$("footer.bd-footer-article").addClass("noprint");
@@ -228,8 +191,6 @@ window.toggleFullScreen = toggleFullScreen;
228191
/**
229192
* Set up functions to load when the DOM is ready
230193
*/
231-
sbRunWhenDOMLoaded(initTooltips);
232194
sbRunWhenDOMLoaded(initTocHide);
233-
sbRunWhenDOMLoaded(initRTDObserver);
234195
sbRunWhenDOMLoaded(addNoPrint);
235196
sbRunWhenDOMLoaded(setMode);

0 commit comments

Comments
 (0)