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

Add custom error pages #83

Merged
merged 3 commits into from
Sep 14, 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
2 changes: 1 addition & 1 deletion docs/src/coding-conventions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Coding Conventions

1. All files should end with a new line character.
1. Python code should be formatted with [black](https://github.com/psf/black).
1. Python code should be formatted with [ruff](https://github.com/astral-sh/ruff).
Copy link
Member

Choose a reason for hiding this comment

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

👌

19 changes: 19 additions & 0 deletions export_base_hugo/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ define "main" }}
<main>
<h1>404</h1>
<h2>Page Not Found</h2>
<p>The URL you requested does not exist on this blog. Got lost?</p>
<p><a href="#" onclick="history.back();">← Go back</a> or return to the <a href="{{ .Site.Home.RelPermalink }}">homepage</a>.</p>
</main>

<footer>
{{- with .Site.GetPage "/" }}
{{- with .OutputFormats.Get "rss" }}
<p>
Subscribe via
{{ printf `<a href=%q title=%q>RSS</a>.` .Permalink site.Title | safeHTML }}
</p>
{{- end }}
{{- end }}
</footer>
{{ end }}
15 changes: 15 additions & 0 deletions export_base_zola/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'index.html' %}

{% block title %}404 — Page Not Found{% endblock title %}

{% block content %}
<main>
<h1>404</h1>
<h2>Page Not Found</h2>
<p>The URL you requested does not exist on this blog. Got lost?</p>
<p><a href="#" onclick="history.back();">← Go back</a> or return to the <a href="/">homepage</a>.</p>
</main>
<footer>
Subscribe via <a href="/{{ config.feed_filename }}">RSS</a>.
</footer>
{% endblock content %}
3 changes: 1 addition & 2 deletions export_base_zola/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ <h1>{{ config.title }}</h1>
</main>

<footer>
--
<br><a href="/{{ config.feed_filename }}">RSS</a>
Subscribe via <a href="/{{ config.feed_filename }}">RSS</a>.
</footer>
{% endblock content %}

Expand Down
2 changes: 1 addition & 1 deletion export_base_zola/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ <h1 class="posts-item-title" itemprop="name headline">
</article>
</main>
<footer>
<a href="/">← archive</a>
Subscribe via <a href="/{{ config.feed_filename }}">RSS</a>.
</footer>
{% endblock content %}
17 changes: 17 additions & 0 deletions main/templates/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'main/layout.html' %}

{% block title %}400 — Bad Request{% endblock %}

{% block content %}
<main>
<h1>400</h1>
<h2>Bad Request</h2>
<p>You made a request in a way that we don't understand. That's all we know.</p>
<p><a href="#" onclick="history.back();">← Go back</a> or return to the <a href="{% url 'index' %}">homepage</a>.</p>
</main>

{% include 'partials/error_webring.html' %}

{% include 'partials/error_footer_blog.html' %}

{% endblock %}
17 changes: 17 additions & 0 deletions main/templates/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'main/layout.html' %}

{% block title %}403 — Permission Denied{% endblock %}

{% block content %}
<main>
<h1>403</h1>
<h2>Permission Denied</h2>
<p>Looks like you tried to do something you're not allowed to. Oops?</p>
<p><a href="#" onclick="history.back();">← Go back</a> or return to the <a href="{% url 'index' %}">homepage</a>.</p>
</main>

{% include 'partials/error_webring.html' %}

{% include 'partials/error_footer_blog.html' %}

{% endblock %}
17 changes: 17 additions & 0 deletions main/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'main/layout.html' %}

{% block title %}404 — Page Not Found{% endblock %}

{% block content %}
<main>
<h1>404</h1>
<h2>Page Not Found</h2>
<p>The URL you requested does not exist on this blog. Got lost?</p>
<p><a href="#" onclick="history.back();">← Go back</a> or return to the <a href="{% url 'index' %}">homepage</a>.</p>
</main>

{% include 'partials/error_webring.html' %}

{% include 'partials/error_footer_blog.html' %}

{% endblock %}
17 changes: 17 additions & 0 deletions main/templates/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'main/layout.html' %}

{% block title %}500 — Internal Server Error{% endblock %}

{% block content %}
<main>
<h1>500</h1>
<h2>Internal Server Error</h2>
<p>An error occurred processing your request. That's all we know.</p>
<p><a href="#" onclick="history.back();">← Go back</a> or return to the <a href="{% url 'index' %}">homepage</a>.</p>
</main>

{% include 'partials/error_webring.html' %}

{% include 'partials/error_footer_blog.html' %}

{% endblock %}
7 changes: 7 additions & 0 deletions main/templates/partials/error_footer_blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<footer>
{{ request.blog_user.subscribe_note_as_html|safe }}

{% if request.blog_user.footer_note %}
{{ request.blog_user.footer_note_as_html|safe }}
{% endif %}
</footer>
20 changes: 20 additions & 0 deletions main/templates/partials/error_webring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% if request.blog_user.webring_prev_url or request.blog_user.webring_url or request.blog_user.webring_next_url %}
<section class="webring">
{% if request.blog_user.webring_prev_url %}
<a href="{{ request.blog_user.webring_prev_url }}">← Previous</a>
{% endif %}
<div>
{% if request.blog_user.webring_url %}
<a href="{{ request.blog_user.webring_url }}" class="webring-name">
{{ request.blog_user.webring_name|default_if_none:'Webring' }}
</a>
{% else %}
{{ request.blog_user.webring_name|default_if_none:'' }}
{% endif %}
</div>
{% if request.blog_user.webring_next_url %}
<a href="{{ request.blog_user.webring_next_url }}">Next →</a>
{% endif %}
</section>
{% endif %}
8 changes: 8 additions & 0 deletions main/views/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def export_zola(request):
zola_post = zola_post_file.read()
with open("./export_base_zola/_index.md") as zola_content_index_file:
zola_content_index = zola_content_index_file.read()
with open("./export_base_zola/404.html") as zola_404_file:
zola_404 = zola_404_file.read()

# get all user posts and add them into export_posts encoded
posts = models.Post.objects.filter(owner=request.user)
Expand All @@ -113,6 +115,7 @@ def export_zola(request):
export_archive.writestr(export_name + "/static/style.css", zola_styles)
export_archive.writestr(export_name + "/templates/index.html", zola_index)
export_archive.writestr(export_name + "/templates/post.html", zola_post)
export_archive.writestr(export_name + "/templates/404.html", zola_404)
export_archive.writestr(
export_name + "/content/_index.md", zola_content_index
)
Expand Down Expand Up @@ -151,6 +154,8 @@ def export_hugo(request):
hugo_index = hugo_index_file.read()
with open("./export_base_hugo/baseof.html") as hugo_baseof_file:
hugo_baseof = hugo_baseof_file.read()
with open("./export_base_hugo/404.html") as hugo_404_file:
hugo_404 = hugo_404_file.read()

# get all user posts and add them into export_posts encoded
posts = models.Post.objects.filter(owner=request.user)
Expand Down Expand Up @@ -179,6 +184,9 @@ def export_hugo(request):
export_archive.writestr(
export_name + "/themes/mataroa/layouts/index.html", hugo_index
)
export_archive.writestr(
export_name + "/themes/mataroa/layouts/404.html", hugo_404
)
export_archive.writestr(
export_name + "/themes/mataroa/layouts/_default/single.html",
hugo_single,
Expand Down
Loading