Skip to content

Commit

Permalink
Fix dirhtml folder creation (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTripleV authored Nov 12, 2020
1 parent 5f53089 commit fe953a4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
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":
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

0 comments on commit fe953a4

Please sign in to comment.