Skip to content

Commit

Permalink
feat: add 404 layout
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Apr 15, 2024
1 parent b4f54a3 commit 4ddc68d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/404.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:orphan:
:layout: 404

404
===

The requested URL was not found on this site.
1 change: 0 additions & 1 deletion docs/_public/404.html

This file was deleted.

3 changes: 3 additions & 0 deletions docs/customisation/layouts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ This template offers a special container for buttons:
`Docs </install/>`_
`GitHub <https://github.com/lepture/shibuya>`_
404 layout
~~~~~~~~~~
11 changes: 11 additions & 0 deletions src/shibuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from sphinx.application import Sphinx
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
from .context import (
normalize_pageurl,
normalize_localtoc,
Expand Down Expand Up @@ -59,6 +60,16 @@ def _initialize_builder(app: Sphinx):
if isinstance(app.builder, StandaloneHTMLBuilder):
app.builder.highlighter.formatter = WrapLineFormatter

if isinstance(app.builder, DirectoryHTMLBuilder):
_get_outfilename = app.builder.get_outfilename

def get_outfilename(pagename: str) -> str:
if pagename == '404':
return (Path(app.builder.outdir) / '404.html').resolve()
return _get_outfilename(pagename)

app.builder.get_outfilename = get_outfilename


def setup(app: Sphinx):
"""Entry point for sphinx theming."""
Expand Down
28 changes: 28 additions & 0 deletions src/shibuya/theme/shibuya/layout/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{%- extends "layout.html" -%}

{% block extrahead %}
<style>
.not-found {
padding-top: calc(30vh - var(--sy-s-offset-top));
text-align: center;
}
.not-found-back .i-icon {
transform: rotate(180deg);
}
.yue a.headerlink {
display: none;
}
</style>
{% endblock %}

{% block body %}
<div class="not-found">
{{ body }}
<div class="not-found-back">
<a href="{{ pathto(root_doc) }}">
<i class="i-icon chevron"></i>
<span>Back to home</span>
</a>
</div>
</div>
{% endblock %}

0 comments on commit 4ddc68d

Please sign in to comment.