Skip to content

do not create 404 page for embedded (e.g. ePub) #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2024
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
6 changes: 3 additions & 3 deletions notfound/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def html_collect_pages(app):
:param app: Sphinx Application
:type app: sphinx.application.Sphinx
"""
if app.config.notfound_pagename in app.env.titles:
# There is already a ``404.rst`` file rendered.
# Skip generating our default one.
if app.builder.embedded or app.config.notfound_pagename in app.env.titles:
# Building embedded (e.g. htmlhelp or ePub) or there is already a ``404.rst``
# file rendered. Skip generating our default one.
return []

return [(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_404_page_created(app, status, warning):
path = app.outdir / '404.html'
assert path.exists()

@pytest.mark.sphinx('epub', srcdir=srcdir)
def test_404_page_not_created(app, status, warning):
assert app.builder.embedded
app.build()
path = app.outdir / '404.html'
assert not path.exists()

@pytest.mark.sphinx(srcdir=srcdir)
def test_default_settings(app, status, warning):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ envlist =
deps =
pytest
pdbpp
defusedxml
.
sphinx5: sphinx<6.0
sphinx6: sphinx<7.0
Expand Down