diff --git a/doc/source/conf.py b/doc/source/conf.py index 6a61257a..55bd759a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -11,8 +11,8 @@ ansys_logo_black, ansys_logo_white, ansys_logo_white_cropped, + generate_404, latex, - page_404, watermark, ) @@ -33,6 +33,12 @@ "additional_breadcrumbs": [ ("Ansys Internal Developer Portal", "https://dev.docs.ansys.com"), ], + "external_links": [ + { + "url": "https://github.com/ansys/ansys-sphinx-theme/releases", + "name": "Changelog", + }, + ], } html_short_title = html_title = "Ansys Sphinx Theme" @@ -104,4 +110,7 @@ latex_elements = {"preamble": latex.generate_preamble(html_title)} # Not found page -notfound_template = page_404 +notfound_context = { + "body": generate_404(), +} +notfound_no_urls_prefix = True diff --git a/doc/source/index.rst b/doc/source/index.rst index 1cf1732a..6f8d8af1 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -11,4 +11,3 @@ Ansys Sphinx Theme documentation |version| getting_started/index.rst user_guide/index.rst - diff --git a/doc/source/user_guide/404_page.rst b/doc/source/user_guide/404_page.rst index 411e78ed..169c6789 100644 --- a/doc/source/user_guide/404_page.rst +++ b/doc/source/user_guide/404_page.rst @@ -33,28 +33,29 @@ your ``conf.py`` file: "notfound.extension", ] - # Add a contact mail to the theme options - html_theme_options = { - ..., - "contact_mail": "pyansys.support@ansys.com", - } - Configure your 404 page ----------------------- You can use the default 404 page that the ``ansys-sphinx-theme`` package supplies -or create and use a custom 404 page. +or create and use a custom 404 page. Use the default 404 page ~~~~~~~~~~~~~~~~~~~~~~~~ -To use the default 404 page, add the following lines in the ``conf.py`` file: +To use the default 404 page, you can use the ``generate_404`` function in the +``ansys_sphinx_theme`` module to create and use a custom cover page: -.. code-block:: +.. code-block:: python - from ansys_sphinx_theme import page_404 + from ansys_sphinx_theme import generate_404 # Configure sphinx-notfound-page - notfound_template = page_404 + notfound_context = { + 'body': generate_404(, + , + , + + ) + } .. _sphinx-notfound-page: https://sphinx-notfound-page.readthedocs.io/en/latest/index.html diff --git a/src/ansys_sphinx_theme/__init__.py b/src/ansys_sphinx_theme/__init__.py index 2658eb72..460639b4 100644 --- a/src/ansys_sphinx_theme/__init__.py +++ b/src/ansys_sphinx_theme/__init__.py @@ -2,7 +2,9 @@ import os from pathlib import Path -__version__ = "0.7.0" +from ansys_sphinx_theme.latex import generate_404 # noqa: F401 + +__version__ = "0.7.1" # get location of this directory _this_path = os.path.dirname(os.path.realpath(__file__)) diff --git a/src/ansys_sphinx_theme/latex/404.html b/src/ansys_sphinx_theme/latex/404.html new file mode 100644 index 00000000..e139d704 --- /dev/null +++ b/src/ansys_sphinx_theme/latex/404.html @@ -0,0 +1,5 @@ +{% block content %}

Page Not Found

+

Sorry, we couldn't find that page. Error code 404.

+

You can try using the search box above or check our menu on the left hand side of this page.

+

If neither of those options work, please create a Github issue ticket in {{project_name}}.

+

Or try sending a mail to {{team_name}}

.{% endblock %} diff --git a/src/ansys_sphinx_theme/latex/__init__.py b/src/ansys_sphinx_theme/latex/__init__.py index c896902e..572c36a1 100644 --- a/src/ansys_sphinx_theme/latex/__init__.py +++ b/src/ansys_sphinx_theme/latex/__init__.py @@ -7,6 +7,7 @@ LATEX_SUBPKG = Path(os.path.dirname(os.path.realpath(__file__))) COVER_TEX = LATEX_SUBPKG / "cover.tex" +PAGE_404 = LATEX_SUBPKG / "404.html" def generate_preamble(title, watermark="watermark", date=None): @@ -46,3 +47,37 @@ def generate_preamble(title, watermark="watermark", date=None): ) template = latex_jinja_env.get_template(".") return template.render(variables) + + +def generate_404( + owner="ansys", + project_name="ansys-sphinx-theme", + mail_id="pyansys.support@ansys.com", + team_name="PyAnsys", +): + """Generate the html body for 404 page. + + Parameters + ---------- + owner : str, default: "ansys" + GitHub organisation in which the project belongs to. + project_name : str, default: "ansys-sphinx-theme" + Name of the project. + mail_id : str, default: "pyansys.support@ansys.com" + E-mail address to contact. + team_name : str, default: "PyAnsys" + Name of the team. + + Returns + ------- + str + A string representing the html source code for the 404 page. + + """ + issue_page = f"https://github.com/{owner}/{project_name}/issues/" + variables = dict( + issue_page=issue_page, project_name=project_name, mail_id=mail_id, team_name=team_name + ) + html_env = jinja2.Environment(loader=jinja2.FileSystemLoader(PAGE_404)) + template = html_env.get_template(".") + return template.render(variables)