From f2f8a235c8d04f36d75dc68e8c5bb2d64b804a4c Mon Sep 17 00:00:00 2001 From: David Bailey Date: Mon, 18 Dec 2023 16:00:28 +0100 Subject: [PATCH] feat: :sparkles: properly utilise 404 page again --- www/router.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/www/router.php b/www/router.php index 04388c8..641ec70 100644 --- a/www/router.php +++ b/www/router.php @@ -34,9 +34,7 @@ $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { $SURI = $_SERVER['REQUEST_URI']; -if($SURI == '/') { - echo $twig->render('root.html'); -} elseif(preg_match('/^\/api\/admin/', $SURI)) { +if(preg_match('/^\/api\/admin/', $SURI)) { header('Content-Type: application/json'); $user_api_key = ''; @@ -82,6 +80,18 @@ if($SURI == '/') { } elseif(true) { $post = $adapter->get_post_by_path($SURI); + if(!$post['found']) { + echo $twig->render('post_types/rrror.html',[ + "error_code" => '404 Hoard not found!', + "error_description" => "Well, we searched + far and wide for `" . $SURI . "` but + somehow it must have gotten lost... Sorry!", + "post" => $post + ]); + + exit(0); + } + if($post['post_metadata']['type'] == 'directory') { if(preg_match('/^(.*[^\/])((?:#.*)?)$/', $SURI, $match)) { header('Location: ' . $match[1] . '/' . $match[2]);