my php website :D https://j0.lol
1<?php
2
3declare(strict_types=1);
4
5# https://stackoverflow.com/a/74790265
6$commit_hash = exec(
7 "cd " .
8 $_SERVER["DOCUMENT_ROOT"] .
9 " && awk '{ print $1 }' ./.git/FETCH_HEAD"
10);
11
12global $commit_hash;
13
14require_once "vendor/autoload.php";
15require_once "posts/post-list.php";
16require_once "extra_funcs.php";
17
18global $router;
19
20function fragment(string $name): void
21{
22 require_once __DIR__ . "/routes/fragments/" . $name . ".php";
23}
24
25$router = new AltoRouter();
26
27/**
28 * This can be useful if you're using PHP's built-in web server, to serve files like images or css
29 * @link https://secure.php.net/manual/en/features.commandline.webserver.php
30 */
31if (
32 file_exists($_SERVER["SCRIPT_FILENAME"]) &&
33 pathinfo($_SERVER["SCRIPT_FILENAME"], PATHINFO_EXTENSION) !== "php"
34) {
35 return;
36}
37
38try {
39 $router->map("GET", "/", "routes/home.php", "index");
40 $router->map("GET", "/blog", "routes/blog-index.php", "blog-index");
41 $router->map(
42 "GET",
43 "/blog/[*:post_slug]",
44 "routes/blog-post.php",
45 "blog-post"
46 );
47 $router->map("GET", "/contact", "routes/contact.php", "contact");
48 $router->map("GET", "/projects", "routes/projects.php", "projects");
49 $router->map("GET", "/friends", "routes/88x31-wall.php", "friends");
50 $router->map("GET", "/feed[.xml]?", "routes/feed.php", "feed");
51} catch (Exception $e) {
52 echo $e;
53}
54
55// Match the current request
56$match = $router->match(urldecode($_SERVER["REQUEST_URI"]));
57if ($match) {
58 foreach ($match["params"] as &$param) {
59 ${key($match["params"])} = $param;
60 }
61 require_once $match["target"];
62} else {
63 http_response_code(404);
64 exit("Page not found");
65}