Have a different 404 page for pages and posts

This commit is contained in:
Evie Viau-Chow-Stuart 2023-02-05 20:19:07 -08:00
parent 75cc11741e
commit 427ad62b3b
Signed by: evie
GPG key ID: 928652CDFCEC8099
5 changed files with 30 additions and 6 deletions

View file

@ -41,8 +41,17 @@ pub(crate) struct PostTemplate {
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "notfound.html")] #[template(path = "pagenotfound.html")]
pub(crate) struct NotFoundTemplate { pub(crate) struct PageNotFoundTemplate {
menu: Vec<menu_entry::Model>,
slug: String,
year: String,
settings: settings::Model
}
#[derive(Template)]
#[template(path = "postnotfound.html")]
pub(crate) struct PostNotFoundTemplate {
menu: Vec<menu_entry::Model>, menu: Vec<menu_entry::Model>,
slug: String, slug: String,
year: String, year: String,

View file

@ -10,7 +10,7 @@ use sea_orm::*;
use chrono::{Utc, Datelike}; use chrono::{Utc, Datelike};
use super::{PageTemplate, NotFoundTemplate}; use super::{PageTemplate, PageNotFoundTemplate};
pub(crate) async fn resolver( pub(crate) async fn resolver(
Path(slug): Path<String>, Path(slug): Path<String>,
@ -45,7 +45,7 @@ pub(crate) async fn resolver(
Ok(page_result) => { Ok(page_result) => {
match page_result { match page_result {
Some(page_result) => page_result, Some(page_result) => page_result,
None => return (StatusCode::NOT_FOUND, NotFoundTemplate { slug, year: Utc::now().date_naive().year().to_string(), menu, settings }).into_response(), None => return (StatusCode::NOT_FOUND, PageNotFoundTemplate { slug, year: Utc::now().date_naive().year().to_string(), menu, settings }).into_response(),
} }
}, },
Err(e) => { Err(e) => {

View file

@ -10,7 +10,7 @@ use sea_orm::*;
use chrono::{Utc, Datelike}; use chrono::{Utc, Datelike};
use super::{PostTemplate, NotFoundTemplate}; use super::{PostTemplate, PostNotFoundTemplate};
pub(crate) async fn resolver( pub(crate) async fn resolver(
Path(slug): Path<String>, Path(slug): Path<String>,
@ -45,7 +45,7 @@ pub(crate) async fn resolver(
Ok(post_result) => { Ok(post_result) => {
match post_result { match post_result {
Some(post_result) => post_result, Some(post_result) => post_result,
None => return (StatusCode::NOT_FOUND, NotFoundTemplate { slug, year: Utc::now().date_naive().year().to_string(), menu, settings }).into_response(), None => return (StatusCode::NOT_FOUND, PostNotFoundTemplate { slug, year: Utc::now().date_naive().year().to_string(), menu, settings }).into_response(),
} }
}, },
Err(e) => { Err(e) => {

View file

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block title %}404{% endblock %}
{% block description %}
This post wasn't found!
{% endblock %}
{% block content %}
<h1>Post not found!</h1>
<p><code>{{ slug }}</code> was not found! Would you like to view other <a href="/posts">posts</a> or go <a href="/">home</a>?</p>
{% endblock %}