Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fixes jupyter-book/jupyter-book#1414

* (use "git restore --staged <file>..." to unstage)
modified:   .pre-commit-config.yaml
modified:   sphinx_external_toc/events.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Angus Hollands <goosey15@gmail.com>
  • Loading branch information
3 people committed Oct 29, 2023
1 parent 31d28ea commit 8fbb76c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Contributing

`sphinx-external-toc` is part of the executablebooks project, who also are responsible for `jupyter-book`.

We're excited you're here and want to contribute.

The Jupyter Book project is run by a community of people like you, we'd love to have you
help out!

Please take a look at the [Jupyter Book contributor guide](https://jupyterbook.org/en/stable/contribute/intro.html)
which steps you through the codebase and how to contribute to this project.
If you have any questions that aren't answered there, please let us know by
[opening an issue][link_issues]!

Thank you for you interest in contributing ✨
13 changes: 9 additions & 4 deletions sphinx_external_toc/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,18 @@ def ensure_index_file(app: Sphinx, exception: Optional[Exception]) -> None:
exception is not None
or "html" not in app.builder.format
or app.config.master_doc == "index"
# TODO rewrite the redirect if master_doc has changed since last build
# TODO: rewrite the redirect if master_doc has changed since last build
or index_path.exists()
):
return

root_name = remove_suffix(app.config.master_doc, app.config.source_suffix)
# TODO the other way to do this would be to
# simply copy the contents of the root file? (this method was taken from jupyter-book)
redirect_text = f'<meta http-equiv="Refresh" content="0; url={root_name}.html" />\n'

if app.builder.name == "html":
redirect_url = f"{root_name}.html"
elif app.builder.name == "dirhtml":
redirect_url = f"{root_name}/index.html"

redirect_text = f'<meta http-equiv="Refresh" content="0; url={redirect_url}" />\n'
index_path.write_text(redirect_text, encoding="utf8")
logger.info("[etoc] missing index.html written as redirect to '%s.html'", root_name)

0 comments on commit 8fbb76c

Please sign in to comment.