Skip to content

Commit fe953a4

Browse files
authored
Fix dirhtml folder creation (#37)
1 parent 5f53089 commit fe953a4

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

sphinxext/rediraffe.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,9 @@ def build_redirects(app: Sphinx, exception: Union[Exception, None]) -> None:
211211
redirect_to = src_redirect_to.with_suffix("")
212212

213213
if type(app.builder) == DirectoryHTMLBuilder:
214-
master_doc = Path(app.config.master_doc).with_suffix("")
215-
if redirect_from != master_doc:
214+
if redirect_from.name != "index":
216215
redirect_from = redirect_from / "index"
217-
if redirect_to != master_doc:
216+
if redirect_to.name != "index":
218217
redirect_to = redirect_to / "index"
219218

220219
redirect_from = redirect_from.with_suffix(".html")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extensions = ["sphinxext.rediraffe"]
2+
3+
master_doc = "index"
4+
exclude_patterns = ["_build"]
5+
6+
html_theme = "basic"
7+
8+
rediraffe_redirects = "redirects.txt"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Index File
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qq
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
another.rst mydir/index.rst

tests/test_ext.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ def test_simple(self, app: Sphinx, ensure_redirect):
274274
assert app.statuscode == 0
275275
ensure_redirect("another/index.html", "index.html")
276276

277+
@pytest.mark.sphinx("dirhtml", testroot="dirhtml_user_index_files")
278+
def test_index_file_foldering(self, app: Sphinx, ensure_redirect):
279+
app.build()
280+
assert app.statuscode == 0
281+
ensure_redirect("another/index.html", "mydir/index.html")
282+
277283
@pytest.mark.sphinx("dirhtml", testroot="simple", freshenv=False)
278284
def test_simple_rebuild(self, app_params, make_app, ensure_redirect):
279285
args, kwargs = app_params

0 commit comments

Comments
 (0)