Skip to content
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

Ship a basic 404 page #83

Merged
merged 2 commits into from
Jul 27, 2022
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: 6 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ansys_logo_white,
ansys_logo_white_cropped,
latex,
page_404,
watermark,
)

Expand All @@ -28,6 +29,7 @@
# specify the location of your github repo
html_theme_options = {
"github_url": "https://github.com/ansys/ansys-sphinx-theme",
"contact_mail": "pyansys.support@ansys.com",
"additional_breadcrumbs": [
("Ansys Internal Developer Portal", "https://dev.docs.ansys.com"),
],
Expand All @@ -41,6 +43,7 @@
"sphinx.ext.autosummary",
"numpydoc",
"sphinx.ext.intersphinx",
"notfound.extension",
"sphinx_copybutton",
"ansys_sphinx_theme",
]
Expand Down Expand Up @@ -99,3 +102,6 @@
# change the preamble of latex with customized title page
# variables are the title of pdf, watermark
latex_elements = {"preamble": latex.generate_preamble(html_title)}

# Not found page
notfound_template = page_404
73 changes: 73 additions & 0 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,76 @@ import and add them in the ``latex_additional_files``:
latex_additional_files = [
watermark, ansys_logo_white, ansys_logo_white_cropped
]


Customizing 404 page
~~~~~~~~~~~~~~~~~~~~
Sphinx does not support a 404 error page by default. For this reason
`sphinx-notfound-page
<https://sphinx-notfound-page.readthedocs.io/en/latest/index.html>`_ was
devised.

Installing and enabling ``sphinx-notfound-page``
------------------------------------------------
Install it by running:

.. code-block:: text

python -m pip install sphinx-notfound-page

Consider adding this extension to your ``requirements_doc.txt``.

Using the default 404 page
--------------------------
Once installed, enable ``sphinx-notfound-page`` in ``conf.py`` file:

.. code-block:: python

# Add the extension
extensions = [
...,
"notfound.extension",
]

# Add a contact mail to the theme options
html_theme_options = {
...,
"contact_mail": "pyansys.support@ansys.com",
}

To use the base 404 page provided by ``ansys-sphinx-theme``, once
`sphinx-notfound-page`_ has been installed, add the following lines in
``conf.py``:

.. code-block::

from ansys_sphinx_theme import page_404


# Configure sphinx-notfound-page
notfound_template = page_404

.. _sphinx-notfound-page: https://sphinx-notfound-page.readthedocs.io/en/latest/index.html

Custom 404 page
---------------
To create a custom 404 page for your project, start by creating a ``404.rst``
file next to ``conf.py`` file. Make sure you include the ``:orphan:`` attribute
at the top of the ``404.rst`` page to suppress the spurious ``document isn't
included in any toctree`` warning from Sphinx.

.. code-block:: rst

:orphan:

Error 404 Not Found
===================
The page you are requesting does not exist.

Update the ``notfound_template`` variable in ``conf.py`` to the location of your
``404.rst`` file:

.. code-block:: rst

# Configure sphinx-notfound-page
notfound_template = "path/to/404.rst"
1 change: 1 addition & 0 deletions requirements/requirements_doc.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Sphinx==5.0.2
numpydoc==1.4.0
sphinx-copybutton==0.5.0
sphinx-notfound-page==0.8.3
3 changes: 3 additions & 0 deletions src/ansys_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
watermark = os.path.join(_this_path, "static", "watermark.pdf")
ansys_logo_black = os.path.join(_this_path, "static", "ansys_logo_black_cropped.jpg")

# Enable default 404 page
page_404 = os.path.join(_this_path, "static", "404.rst")

html_logo = pyansys_logo_black

CSS_FILENAME = "ansys_sphinx_theme.css"
Expand Down
7 changes: 7 additions & 0 deletions src/ansys_sphinx_theme/static/404.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:orphan:

Oops!
=====
This is unexpected. The page you are requesting does not exist.

If this page should exist, please contact `{{ theme_contact_mail }} <mailto:{{ theme_contact_mail }}`_.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that some projects may not be linked to GitHub (see #38), we agreed on adding a new theme variable named contact_mail which is used in the 404.rst file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will just have to start enforcing its use across the different docs, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right. Since this is a third party extension, we need to configure it manually. Same happens with the numpydoc, for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#OpeningPRsEverywhere

1 change: 1 addition & 0 deletions src/ansys_sphinx_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ inherit = pydata_sphinx_theme
pygments_style = friendly

[options]
contact_mail =
github_url = https://github.com/ansys
logo.link = https://www.ansys.com/
show_breadcrumbs = True
Expand Down