diff --git a/sphinxext/rediraffe.py b/sphinxext/rediraffe.py index e43227d..51fb7d8 100644 --- a/sphinxext/rediraffe.py +++ b/sphinxext/rediraffe.py @@ -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": redirect_to = redirect_to / "index" redirect_from = redirect_from.with_suffix(".html") diff --git a/tests/roots/ext/test-dirhtml_user_index_files/conf.py b/tests/roots/ext/test-dirhtml_user_index_files/conf.py new file mode 100644 index 0000000..8136c0e --- /dev/null +++ b/tests/roots/ext/test-dirhtml_user_index_files/conf.py @@ -0,0 +1,8 @@ +extensions = ["sphinxext.rediraffe"] + +master_doc = "index" +exclude_patterns = ["_build"] + +html_theme = "basic" + +rediraffe_redirects = "redirects.txt" diff --git a/tests/roots/ext/test-dirhtml_user_index_files/index.rst b/tests/roots/ext/test-dirhtml_user_index_files/index.rst new file mode 100644 index 0000000..e5616f3 --- /dev/null +++ b/tests/roots/ext/test-dirhtml_user_index_files/index.rst @@ -0,0 +1 @@ +Index File \ No newline at end of file diff --git a/tests/roots/ext/test-dirhtml_user_index_files/mydir/index.rst b/tests/roots/ext/test-dirhtml_user_index_files/mydir/index.rst new file mode 100644 index 0000000..f3736ef --- /dev/null +++ b/tests/roots/ext/test-dirhtml_user_index_files/mydir/index.rst @@ -0,0 +1 @@ +qq \ No newline at end of file diff --git a/tests/roots/ext/test-dirhtml_user_index_files/redirects.txt b/tests/roots/ext/test-dirhtml_user_index_files/redirects.txt new file mode 100644 index 0000000..2543c50 --- /dev/null +++ b/tests/roots/ext/test-dirhtml_user_index_files/redirects.txt @@ -0,0 +1 @@ +another.rst mydir/index.rst \ No newline at end of file diff --git a/tests/test_ext.py b/tests/test_ext.py index 2640d95..08909dc 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -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