Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
rev: v0.16.6
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/rbubley/mirrors-prettier
rev: 39e2973981e6d2f9b6c543b0086a2d2393abdc89 # frozen: v3.9.4
rev: 0ee178619d696787ca73d210cc191d720868c631 # frozen: v3.9.6
hooks:
- id: prettier
types_or: [scss, javascript]

- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.3
hooks:
- id: codespell
exclude: >
Expand Down
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ Note that this doesn't imply any new long-term support or stability, we will con

**`single_page` is deprecated**. If you'd like to restore the old behavior (hiding sidebars), then use the following configuration in your `conf.py`:
```python
html_sidebars = {
"**": []
}
html_sidebars = {"**": []}
```

### Contributors to this release
Expand Down
12 changes: 6 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -- Project information -----------------------------------------------------
import os
from urllib.request import urlopen
from pathlib import Path
from datetime import datetime
from pathlib import Path
from urllib.request import urlopen

project = "Sphinx Book Theme"
copyright = str(datetime.now().year)
Expand Down Expand Up @@ -198,7 +198,7 @@

# -- Download latest theme elements page from PyData -----------------------------

path_pydata_content = "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/user_guide/theme-elements.md" # noqa
path_pydata_content = "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/user_guide/theme-elements.md"
path_content_file = Path(__file__).parent / "content/pydata-content-blocks.md"
if not path_content_file.exists():
with urlopen(path_pydata_content) as resp:
Expand All @@ -208,8 +208,8 @@
content[ix_title] = "# PyData Theme Elements"
content.insert(
ix_title + 1,
"\nThis is a collection of content blocks with special support from this theme's parent theme, [the PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/theme-elements.html)\n", # noqa
) # noqa
"\nThis is a collection of content blocks with special support from this theme's parent theme, [the PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/theme-elements.html)\n",
)
content = "\n".join(content)
# Replace a relative link in the pydata docs w/ the respective one here
content = content.replace("../examples/pydata.ipynb", "notebooks.md")
Expand All @@ -230,7 +230,7 @@ def setup(app):
app.add_css_file("https://assets.readthedocs.org/static/css/badge_only.css")

# Create the dummy data file so we can link it
# ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js # noqa: E501
# ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js
app.add_js_file("rtd-data.js")
app.add_js_file(
"https://assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js",
Expand Down
4 changes: 3 additions & 1 deletion docs/contributing/subthemes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ For example, here's a Python snippet that reuses this function:
```python
from sphinx_book_theme import hash_assets_for_files


def hash_html_assets(app, pagename, templatename, context, doctree):
assets = ["styles/your-css-asset.css", "scripts/your-js-asset.js"]
STATIC_PATH = "path to your theme's static folder"
hash_assets_for_files(assets, STATIC_PATH, context)


def setup(app):
app.connect("html-page-context", hash_html_assets)
app.connect("html-page-context", hash_html_assets)
```

## Defining your own CSS
Expand Down
12 changes: 6 additions & 6 deletions docs/contributing/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ For example:

```python
if sphinx_build.software_versions == ".sphinx8":
foo
foo
elif sphinx_build.software_versions == ".sphinx9":
bar
bar
```

### Regression tests
Expand Down Expand Up @@ -105,9 +105,9 @@ Do we gain something meaningful by testing both major versions of Sphinx, or is

```python
file_regression.check(
html.prettify(),
basename="foo",
extension=f"{sphinx_build.software_versions}.html",
encoding="utf8",
html.prettify(),
basename="foo",
extension=f"{sphinx_build.software_versions}.html",
encoding="utf8",
)
```
6 changes: 3 additions & 3 deletions docs/scripts/update_kitchen_sink.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from urllib.request import urlopen
from pathlib import Path
from urllib.request import urlopen

EXTRA_MESSAGE = """\

Expand All @@ -14,7 +14,7 @@
:color: primary

Go to Sphinx Themes
""" # noqa
"""

kitchen_sink_files = [
"admonitions.rst",
Expand All @@ -32,7 +32,7 @@
path_sink = Path(__file__).parent.parent / "reference" / "kitchen-sink"
for ifile in kitchen_sink_files:
print(f"Reading {ifile}...")
url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}" # noqa
url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}"
text = urlopen(url).read().decode()
# The sphinx-themes docs expect Furo to be installed, so we overwrite w/ this path
text = text.replace("src/furo", "src/sphinx_book_theme")
Expand Down
5 changes: 1 addition & 4 deletions docs/sections/footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ It adds the `_templates` folder to Sphinx's templates path, and adds the templat

```python
templates_path = ["_templates"]
html_theme_options = {
"footer_start": ["test.html"],
"footer_end": ["test.html"]
}
html_theme_options = {"footer_start": ["test.html"], "footer_end": ["test.html"]}
```
4 changes: 1 addition & 3 deletions docs/sections/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ Make sure that `_templates` is [on your templates path](https://www.sphinx-doc.o
**Add the following to `conf.py`**:

```python
html_theme_options = {
"navbar_end": ["mybutton.html"]
}
html_theme_options = {"navbar_end": ["mybutton.html"]}
```

Your header should now be visible, and the `mybutton.html` content should now show up in the upper-right.
Expand Down
8 changes: 2 additions & 6 deletions docs/sections/sidebar-primary.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ To do so, use the `html_sidebars` variable in your `conf.py` file. This takes a
For example, the following configuration would include *only the footer* on pages under the `posts/` folder:

```python
html_sidebars = {
"posts/*": ["sbt-sidebar-nav.html"]
}
html_sidebars = {"posts/*": ["sbt-sidebar-nav.html"]}
```

You can also use `**` to apply a set of sidebars to **all** pages of your book. For example:

```python
html_sidebars = {
"**": ["sbt-sidebar-nav.html"]
}
html_sidebars = {"**": ["sbt-sidebar-nav.html"]}
```

See the [Sphinx HTML sidebars documentation](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars) for more information.
Expand Down
8 changes: 2 additions & 6 deletions docs/sections/sidebar-secondary.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ This page describes ways to control and customize the secondary sidebar.
You can rename the title of the in-page table of contents, in the right sidebar:

```python
html_theme_options = {
"toc_title": "{your-title}"
}
html_theme_options = {"toc_title": "{your-title}"}
```

The default value of the title is `Contents`.
Expand All @@ -23,9 +21,7 @@ Normally only the 2nd-level headers of a page are shown in the within-page table
You can show deeper levels by default by using the following configuration, indicating how many levels should be displayed:

```python
html_theme_options = {
"show_toc_level": 2
}
html_theme_options = {"show_toc_level": 2}
```

All headings up to and including the level specified will now be shown regardless of what is displayed on the page.
18 changes: 9 additions & 9 deletions src/sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

import hashlib
import os
from functools import cache, lru_cache
from pathlib import Path
from functools import lru_cache

from docutils import nodes as docutil_nodes
from pydata_sphinx_theme.utils import get_theme_options_dict
from sphinx.application import Sphinx
from sphinx.locale import get_translation
from sphinx.util import logging
from pydata_sphinx_theme.utils import get_theme_options_dict

from ._compat import findall
from ._transforms import HandleFootnoteTransform
from .directives import Margin
from .nodes import SideNoteNode
from .header_buttons import (
prep_header_buttons,
add_header_buttons,
update_sourcename,
prep_header_buttons,
update_context_with_repository_info,
update_sourcename,
)
from .header_buttons.launch import add_launch_buttons
from .header_buttons.source import add_source_buttons
from ._compat import findall
from ._transforms import HandleFootnoteTransform
from .nodes import SideNoteNode

__version__ = "1.5.0.dev"
"""sphinx-book-theme version"""
Expand Down Expand Up @@ -74,7 +74,7 @@ def add_metadata_to_page(app, pagename, templatename, context, doctree):
context["theme_search_bar_text"] = translation("Search") + "..."


@lru_cache(maxsize=None)
@cache
def _gen_hash(path: str) -> str:
return hashlib.sha1(path.read_bytes()).hexdigest()

Expand Down Expand Up @@ -173,7 +173,7 @@ def check_deprecation_keys(app):
for key in deprecated_config_list:
if key in get_theme_options_dict(app):
SPHINX_LOGGER.warning(
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
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"
f"[{DEFAULT_LOG_TYPE}]",
type=DEFAULT_LOG_TYPE,
)
Expand Down
3 changes: 2 additions & 1 deletion src/sphinx_book_theme/_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from docutils.nodes import Element
from collections.abc import Iterator

from docutils.nodes import Element


def findall(node: Element, *args, **kwargs) -> Iterator[Element]:
# findall replaces traverse in docutils v0.18
Expand Down
4 changes: 2 additions & 2 deletions src/sphinx_book_theme/_compile_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import json
import os
from pathlib import Path
import subprocess
from pathlib import Path

# In case the smodin.io code is different from the Sphinx code
RENAME_LANGUAGE_CODES = {
Expand Down Expand Up @@ -34,7 +34,7 @@ def convert_json(folder=None):
if language in RENAME_LANGUAGE_CODES:
language = RENAME_LANGUAGE_CODES[language]
out_path = (
out_folder / "locales" / language / "LC_MESSAGES" / "booktheme.po" # noqa: E501
out_folder / "locales" / language / "LC_MESSAGES" / "booktheme.po"
)
if not out_path.parent.exists():
out_path.parent.mkdir(parents=True)
Expand Down
10 changes: 6 additions & 4 deletions src/sphinx_book_theme/_transforms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from sphinx.transforms.post_transforms import SphinxPostTransform
from typing import Any

from docutils import nodes as docutil_nodes
from sphinx import addnodes as sphinx_nodes
from pydata_sphinx_theme.utils import get_theme_options_dict
from .nodes import SideNoteNode
from sphinx import addnodes as sphinx_nodes
from sphinx.transforms.post_transforms import SphinxPostTransform

from ._compat import findall
from .nodes import SideNoteNode


class HandleFootnoteTransform(SphinxPostTransform):
Expand All @@ -16,7 +18,7 @@ class HandleFootnoteTransform(SphinxPostTransform):
def run(self, **kwargs: Any) -> None:
theme_options = get_theme_options_dict(self.app)
if theme_options.get("use_sidenotes", False) is False:
return None
return
# Cycle through footnote references, and move their content next to the
# reference. This lets us display the reference in the margin,
# or just below on narrow screens.
Expand Down
6 changes: 2 additions & 4 deletions src/sphinx_book_theme/header_buttons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Generate metadata for header buttons."""

from pydata_sphinx_theme.utils import config_provided_by_user, get_theme_options_dict
from sphinx.errors import SphinxError
from sphinx.locale import get_translation
from pydata_sphinx_theme.utils import config_provided_by_user, get_theme_options_dict

from sphinx.util import logging


LOGGER = logging.getLogger(__name__)
MESSAGE_CATALOG_NAME = "booktheme"
translation = get_translation(MESSAGE_CATALOG_NAME)
Expand Down Expand Up @@ -167,7 +165,7 @@ def update_context_with_repository_info(app):

# If no provider is given, try to infer one from the repo url
if provider == "":
for iprov in default_provider_urls.keys():
for iprov in default_provider_urls:
if iprov in provider_url.lower():
provider = iprov
break
Expand Down
9 changes: 4 additions & 5 deletions src/sphinx_book_theme/header_buttons/launch.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Launch buttons for Binder / Thebe / Colab / etc."""

from pathlib import Path
from typing import Any, Optional
from urllib.parse import urlencode, quote
from shutil import copy2
from typing import Any
from urllib.parse import quote, urlencode

from docutils.nodes import document
from sphinx.application import Sphinx
from sphinx.locale import get_translation
from sphinx.util import logging
from shutil import copy2

from . import get_repo_parts, get_repo_url


SPHINX_LOGGER = logging.getLogger(__name__)

MESSAGE_CATALOG_NAME = "booktheme"
Expand All @@ -24,7 +23,7 @@ def add_launch_buttons(
pagename: str,
templatename: str,
context: dict[str, Any],
doctree: Optional[document],
doctree: document | None,
):
"""Builds a binder link and inserts it in HTML context for use in templating.

Expand Down
4 changes: 2 additions & 2 deletions src/sphinx_book_theme/header_buttons/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def add_source_buttons(app, pagename, templatename, context, doctree):
repo_url, provider = get_repo_url(context)
if provider in ("github", "gitlab"):
if provider == "github":
url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here." # noqa: E501
url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here."
elif provider == "gitlab":
url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here." # noqa: E501
url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here."
repo_buttons.append(
{
"type": "link",
Expand Down
3 changes: 2 additions & 1 deletion src/sphinx_book_theme/nodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, cast

from docutils import nodes
from sphinx.application import Sphinx
from typing import Any, cast


class SideNoteNode(nodes.Element):
Expand Down
Loading
Loading