Skip to content
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
5 changes: 2 additions & 3 deletions sphinxext/rediraffe.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ def build_redirects(app: Sphinx, exception: Union[Exception, None]) -> None:
redirect_to = src_redirect_to.with_suffix("")

if type(app.builder) == DirectoryHTMLBuilder:
master_doc = Path(app.config.master_doc).with_suffix("")
if redirect_from != master_doc:
if redirect_from.name != "index":
redirect_from = redirect_from / "index"
if redirect_to != master_doc:
if redirect_to.name != "index":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if redirect_to.name != "index":

Just a note that this may break in the future. Anyways, the default in Sphinx 2+ is index, so we don't break that many.

redirect_to = redirect_to / "index"

redirect_from = redirect_from.with_suffix(".html")
Expand Down
8 changes: 8 additions & 0 deletions tests/roots/ext/test-dirhtml_user_index_files/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extensions = ["sphinxext.rediraffe"]

master_doc = "index"
exclude_patterns = ["_build"]

html_theme = "basic"

rediraffe_redirects = "redirects.txt"
1 change: 1 addition & 0 deletions tests/roots/ext/test-dirhtml_user_index_files/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Index File
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
qq
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
another.rst mydir/index.rst
6 changes: 6 additions & 0 deletions tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ def test_simple(self, app: Sphinx, ensure_redirect):
assert app.statuscode == 0
ensure_redirect("another/index.html", "index.html")

@pytest.mark.sphinx("dirhtml", testroot="dirhtml_user_index_files")
def test_index_file_foldering(self, app: Sphinx, ensure_redirect):
app.build()
assert app.statuscode == 0
ensure_redirect("another/index.html", "mydir/index.html")

@pytest.mark.sphinx("dirhtml", testroot="simple", freshenv=False)
def test_simple_rebuild(self, app_params, make_app, ensure_redirect):
args, kwargs = app_params
Expand Down