Skip to content

Commit

Permalink
Use sphinx-notfound-page by default to create a generic 404 page
Browse files Browse the repository at this point in the history
We use the sphinx-notfound-page extension to create a generic page for
each project. By default we use the same Maze Found ASCII art, but the
user can customize it by defining specific configs from the sphinx-notfound-page.
  • Loading branch information
humitos committed Feb 4, 2019
1 parent 689ec78 commit f7ce417
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readthedocs/core/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def server_error_404(request, exception=None, template_name='404.html'): # pyli
return response

# Try to serve custom 404 pages if it's a subdomain/cname
if request.subdomain or request.cname:
if getattr(request, 'subdomain', False) or getattr(request, 'cname', False):
return server_error_404_subdomain(request, template_name)

# Return the default 404 page generated by Read the Docs
Expand Down
8 changes: 6 additions & 2 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def install_core_requirements(self):
),
'sphinx-rtd-theme<0.5',
'readthedocs-sphinx-ext<0.6',
'sphinx-notfound-page',
])

cmd = copy.copy(pip_install_cmd)
Expand Down Expand Up @@ -429,7 +430,10 @@ def install_core_requirements(self):
if self.config.doctype == 'mkdocs':
pip_requirements.append('mkdocs')
else:
pip_requirements.append('readthedocs-sphinx-ext')
pip_requirements.extend([
'readthedocs-sphinx-ext',
'sphinx-notfound-page',
])
requirements.extend(['sphinx', 'sphinx_rtd_theme'])

cmd = [
Expand All @@ -443,7 +447,7 @@ def install_core_requirements(self):
cmd.extend(requirements)
self.build_env.run(
*cmd,
cwd=self.checkout_path # noqa - no comma here in py27 :/
cwd=self.checkout_path,
)

pip_cmd = [
Expand Down
13 changes: 13 additions & 0 deletions readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@ if 'extensions' in globals():
extensions.insert(0, "readthedocs_ext.readthedocs")
else:
extensions = ["readthedocs_ext.readthedocs"]


# Define default 404 page body
if 'notfound_context' not in globals():
notfound_context = {
'body': '''
<h1>Page not found</h1>

<p>Sorry, we couldn't find that page.</p>

<p>Try using the search box or go to the <a href="/">homepage</a>.</p>
''',
}
2 changes: 2 additions & 0 deletions readthedocs/rtd_tests/tests/test_doc_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ def test_install_core_requirements_sphinx(self, checkout_path):
'sphinx',
'sphinx-rtd-theme',
'readthedocs-sphinx-ext',
'sphinx-notfound-page',
]
requirements = self.base_requirements + requirements_sphinx
args = self.pip_install_args + requirements
Expand Down Expand Up @@ -1356,6 +1357,7 @@ def test_install_core_requirements_sphinx_conda(self, checkout_path):
pip_requirements = [
'recommonmark',
'readthedocs-sphinx-ext',
'sphinx-notfound-page',
]

args_pip = [
Expand Down

0 comments on commit f7ce417

Please sign in to comment.