refined 404 page

This commit is contained in:
J-onasJones 2024-06-07 01:48:01 +02:00
parent 9dfe5c0dd1
commit 5e66f120f3
5 changed files with 42 additions and 19 deletions

View file

@ -1,6 +1,6 @@
<nav class="navbar">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/#/">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<a href="https://jonasjones.dev" class="sticky-link">Homepage</a>

View file

@ -33,4 +33,5 @@ html, body {
a, p {
font-family: 'JetBrains Mono';
font-size: 20px;
}

View file

@ -1,9 +1,9 @@
import Home from './routes/Home.svelte';
import Lorem from './routes/Lorem.svelte';
import Post from './routes/Post.svelte';
import NotFound from './routes/NotFound.svelte';
export default {
'/': Home,
'/lorem/:repeat': Lorem,
'/post/:year/:month/:day/:title': Post,
'*': NotFound
};

View file

@ -1,11 +1,30 @@
<h1>Not Found</h1>
<p>This route doesn't exist.</p>
<div id="error">
<h1 id="code">404</h1>
<h1 id="msg">Not Found</h1>
<p>This post doesn't exist or has been deleted.</p>
</div>
<style>
h1 {
color: #ff0040;
text-transform: uppercase;
font-size: 4em;
font-weight: 100;
#error {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
text-align: center;
}
#code {
font-family: 'Pixelify Sans';
font-size: 7em;
font-weight: 400;
margin-bottom: 0;
}
#msg {
margin-top: 0;
font-family: 'Libre Barcode 128';
font-size: 5em;
font-weight: 400;
}
</style>

View file

@ -1,15 +1,18 @@
<script lang="ts">
export let params: {repeat?: string} = {};
export let params: {year?: string, month?: string, day?: string, title?: string} = {};
let repeat = 1;
$: {
repeat = 1
if (params?.repeat) {
repeat = parseInt(params.repeat, 10)
if (repeat < 1) {
repeat = 1
}
if (params.year && params.month && params.day && params.title) {
const date = new Date(`${params.year}-${params.month}-${params.day}`);
if (isNaN(date.getTime())) {
// the date is invalid
// navigate to the 404 page
// this is the same as returning { status: 404 } from load()
location.href = '/404';
}
} else {
// the URL is missing some parameters
// navigate to the 404 page
location.href = '/#/404';
}
</script>