Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: templates_path in config was overriding value set in extension #566

Merged
merged 17 commits into from
Jul 15, 2022
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
_build

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a short overview of the general architecture and structure of the repository, to help you orient yourself.

This theme uses [sphinx-theme-builder](https://sphinx-theme-builder.readthedocs.io/en/latest/) as its build backend, and follows the [filesystem layout](https://sphinx-theme-builder.readthedocs.io/en/latest/reference/filesystem-layout/) recommended by it.
This theme uses [sphinx-theme-builder](https://sphinx-theme-builder.readthedocs.io/en/latest/) as its build backend, and follows the [filesystem layout](https://sphinx-theme-builder.readthedocs.io/en/latest/filesystem-layout/) recommended by it.
See below for some more specific sections

```{contents}
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ See the [paragraph markup page](kitchen-sink/paragraph-markup.rst) for more refe

## `ABlog` - Blog post list

[ABlog](https://ablog.readthedocs.io/en/latest/) is a Sphinx extension for blogging with Sphinx.
[ABlog](https://ablog.readthedocs.io/) is a Sphinx extension for blogging with Sphinx.

Here's a sample post list:

Expand Down
14 changes: 13 additions & 1 deletion src/sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ def run(self):
return nodes


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


def setup(app: Sphinx):
# Register theme
theme_dir = get_html_theme_path()
Expand All @@ -176,6 +186,7 @@ def setup(app: Sphinx):

# Events
app.connect("builder-inited", update_thebe_config)
app.connect("config-inited", update_general_config)
app.connect("html-page-context", add_metadata_to_page)
app.connect("html-page-context", hash_html_assets)

Expand All @@ -194,7 +205,8 @@ def setup(app: Sphinx):
# Post-transforms
app.add_post_transform(HandleFootnoteTransform)

# Update templates for sidebar
# Update templates for sidebar, for builds where config-inited is not called
# (does not work in case of jupyter-book)
app.config.templates_path.append(os.path.join(theme_dir, "components"))

return {
Expand Down