make a 404 page

This commit is contained in:
2025-09-24 16:26:30 +02:00
parent c54a1a1762
commit a36f2c86a7
6 changed files with 60 additions and 4 deletions

View File

@@ -2,11 +2,11 @@ use std::convert::Infallible;
use axum::{ use axum::{
body::Body, body::Body,
http::{Request, StatusCode, header}, http::{Request, header},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use crate::website::pages::index::page_index; use crate::website::pages::{index::page_index, notfound::page_notfound};
mod pages; mod pages;
@@ -22,6 +22,6 @@ pub async fn website_service(req: Request<Body>) -> Result<Response, Infallible>
"styles.css" => ([(header::CONTENT_TYPE, "text/css")], STYLES_CSS).into_response(), "styles.css" => ([(header::CONTENT_TYPE, "text/css")], STYLES_CSS).into_response(),
"favicon.svg" => ([(header::CONTENT_TYPE, "image/svg+xml")], FAVICON_SVG).into_response(), "favicon.svg" => ([(header::CONTENT_TYPE, "image/svg+xml")], FAVICON_SVG).into_response(),
"favicon-x64.png" => ([(header::CONTENT_TYPE, "image/png")], FAVICON_X64).into_response(), "favicon-x64.png" => ([(header::CONTENT_TYPE, "image/png")], FAVICON_X64).into_response(),
_ => StatusCode::NOT_FOUND.into_response(), _ => page_notfound().await,
}) })
} }

View File

@@ -1,4 +1,5 @@
pub mod index; pub mod index;
pub mod notfound;
const INTERNAL_SERVER_ERROR_MSG: &str = const INTERNAL_SERVER_ERROR_MSG: &str =
"An internal server error occured while rendering your HTML. Sorry!"; "An internal server error occured while rendering your HTML. Sorry!";

View File

@@ -0,0 +1,19 @@
use askama::Template;
use axum::{
http::StatusCode,
response::{Html, IntoResponse, Response},
};
use crate::website::pages::INTERNAL_SERVER_ERROR_MSG;
#[derive(Template)]
#[template(path = "notfound.html")]
struct PageNotFound;
pub async fn page_notfound() -> Response {
let a = PageNotFound;
match a.render() {
Ok(res) => (StatusCode::OK, Html(res)).into_response(),
Err(_e) => (StatusCode::INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MSG).into_response(),
}
}

20
web/base.html Normal file
View File

@@ -0,0 +1,20 @@
<!doctype html>
<html lang="pl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<link
rel="icon"
type="image/png"
sizes="64x64"
href="favicon-x64.png"
/>
<link href="styles.css" rel="stylesheet" />
<title>{% block title %}{{ title }}{% endblock %}</title>
{% block head %} {% endblock %}
</head>
<body class="min-h-screen flex flex-col">
{% block pagecontent %} {{ pagecontent }} {% endblock %}
</body>
</html>

View File

@@ -1,5 +1,5 @@
<footer <footer
class="w-full h-full border-t border-neutral-300 bg-neutral-100 p-4 flex flex-col" class="w-full h-full border-t border-neutral-300 bg-neutral-100 p-4 flex flex-col mt-auto"
> >
<div class="flex flex-col sm:grid sm:grid-cols-3 gap-8 mx-auto"> <div class="flex flex-col sm:grid sm:grid-cols-3 gap-8 mx-auto">
<section class="max-w-sm w-full"> <section class="max-w-sm w-full">

16
web/notfound.html Normal file
View File

@@ -0,0 +1,16 @@
{% extends "base.html" %} {# # # # # # # # # # # # # # # # # # # # # # # # # #}
{% block title %}gractwo.pl | Błąd 404{% endblock %} {% block pagecontent %}
<div class="mx-auto my-auto sm:flex gap-2">
<div class="size-16 pl-2 sm:pl-0">{% include "gractwo.svg" %}</div>
<div class="px-2">
<h1 class="font-bold text-2xl">Błąd 404</h1>
<p>
Nie ma strony o podanym adresie.
<a class="text-gractwo-blu-dark hover:underline" href="/">Wróć.</a>
</p>
</div>
</div>
{% include "footer.html" %} {# # # # # # # # # # # # # # # # # # # # # # # # #}
{% endblock %}