Skip to content
Open
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
7 changes: 7 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ These values are placed in the :file:`conf.py` of your Sphinx project.
The percentage as an integer representing the accuracy required before
auto redirecting with the ``rediraffewritediff`` builder.

.. confval:: rediraffe_dir_only
:type: :code-py:`bool`
:default: :code-py:`False`

Whether to include ``/index.html`` in destination URLs when using the ``dirhtml``
builder.

Example Config
==============

Expand Down
7 changes: 6 additions & 1 deletion sphinxext/rediraffe.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ def build_redirects(app: Sphinx, exception: Exception | None) -> None:
src_redirect_from.parent / redirect_from_name / 'index.html'
)
if redirect_to_name != 'index':
redirect_to = src_redirect_to.parent / redirect_to_name / 'index.html'
redirect_to = (
src_redirect_to.parent / redirect_to_name
if app.config.rediraffe_dir_only
else src_redirect_to.parent / redirect_to_name / 'index.html'
)

# absolute paths into the build dir
build_redirect_from = Path(app.outdir) / redirect_from
Expand Down Expand Up @@ -472,6 +476,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.add_config_value('rediraffe_branch', '', None)
app.add_config_value('rediraffe_template', None, None)
app.add_config_value('rediraffe_auto_redirect_perc', 100, None)
app.add_config_value('rediraffe_dir_only', False, 'env')

app.add_builder(CheckRedirectsDiffBuilder)
app.add_builder(WriteRedirectsDiffBuilder)
Expand Down
11 changes: 11 additions & 0 deletions tests/roots/ext/test-rediraffe_dir_only/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import annotations

extensions = ['sphinxext.rediraffe']

master_doc = 'index'
exclude_patterns = ['_build']

html_theme = 'basic'

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

@pytest.mark.sphinx('dirhtml', testroot='rediraffe_dir_only')
def test_rediraffe_dir_only(self, app: Sphinx, ensure_redirect):
app.build()
assert app.statuscode == 0
ensure_redirect('another/index.html', 'mypage/')

@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
Loading