Skip to content

Commit

Permalink
Merge pull request #83 from poopsicles/main
Browse files Browse the repository at this point in the history
Add custom error pages
  • Loading branch information
sirodoht authored Sep 14, 2024
2 parents 06795b8 + 4abfcb1 commit 86a781d
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 4 deletions.
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).
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

0 comments on commit 86a781d

Please sign in to comment.