diff --git a/www/blog.php b/www/blog.php index 3f8db06..194bd00 100644 --- a/www/blog.php +++ b/www/blog.php @@ -3,17 +3,15 @@ require_once __DIR__ . '/lib/_index.php'; $id = (int) $_GET['id']; -$path = __DIR__ . "/blog/$id.svg"; -if (!file_exists($path)) { + +$blog = Blog::get($id); +if ($blog === null) { http_response_code(404); require __DIR__ . '/404.php'; exit; } -$svg = file_get_contents($path); -if (str_starts_with($svg, ']+>\s*/', '', $svg); -} +$svgs = $blog->getSVGs(); ?> @@ -26,7 +24,7 @@ if (str_starts_with($svg, ' - Blog + <?= $blog->title ?>
- + + +
diff --git a/www/blog/0.json b/www/blog/0.json index 023c8cb..577c856 100644 --- a/www/blog/0.json +++ b/www/blog/0.json @@ -1,7 +1,7 @@ { - "links": { - "google": "https://google.com", - "handwritten.blog": "https://handwritten.blog", - "blog-lehnert.dev": "mailto:blog@lehnert.dev" - } + "title": "Test: First Blog Entry", + "date": "2025-04-15", + "files": [ + "0.svg" + ] } \ No newline at end of file diff --git a/www/index.php b/www/index.php index 76b28cf..3e0c251 100644 --- a/www/index.php +++ b/www/index.php @@ -4,6 +4,11 @@ require_once __DIR__ . "/lib/_index.php"; [$points, $edges, $sizes] = stars_random(); +$blogs = Blog::getAll(); +usort($blogs, function ($a, $b) { + strtotime($b->date) - strtotime($a->date); +}); + ?> @@ -32,17 +37,20 @@ require_once __DIR__ . "/lib/_index.php"; } main { + color: white; + font-family: "Inter", sans-serif; + pointer-events: none; + } + + .welcome { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 80vh; - color: white; - font-family: "Inter", sans-serif; text-align: center; padding: 2rem; - pointer-events: none; } h1 { @@ -95,16 +103,39 @@ require_once __DIR__ . "/lib/_index.php"; pointer-events: auto; } - .legal-links a { - color: rgb(255, 255, 255); - cursor: pointer; - transition: background 0.3s ease; + a { + color: white; } - .legal-links a:hover { + a:hover { opacity: 0.8; } + .blog-entries { + display: flex; + flex-direction: column; + align-items: center; + padding: 1rem; + gap: 1rem; + } + + .blog-entry { + width: min(90vw, 600px); + background: #303050; + border-left: 4px solid #00ffff; + border-radius: 12px; + box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); + padding: 1rem; + } + + .blog-entry * { + margin: 0; + } + + .blog-entry a { + pointer-events: auto; + } + @keyframes glow { from { @@ -128,30 +159,41 @@ require_once __DIR__ . "/lib/_index.php";
-

Hey, I'm Ludwig 🚀

-

Welcome to my digital playground.

+
+

Hey, I'm Ludwig 🚀

+

Welcome to my digital playground.

- -
diff --git a/www/lib/_index.php b/www/lib/_index.php index 737d7ca..506161a 100644 --- a/www/lib/_index.php +++ b/www/lib/_index.php @@ -2,4 +2,5 @@ require_once __DIR__ . '/style.php'; require_once __DIR__ . '/stars.php'; -require_once __DIR__ . '/fill.php'; \ No newline at end of file +require_once __DIR__ . '/fill.php'; +require_once __DIR__ . '/blog.php'; \ No newline at end of file diff --git a/www/lib/blog.php b/www/lib/blog.php new file mode 100644 index 0000000..4083f81 --- /dev/null +++ b/www/lib/blog.php @@ -0,0 +1,74 @@ +id = $id; + $this->title = $title; + $this->date = $date; + $this->files = $files; + } + + public function formatDate(): string + { + return date("F jS, Y", strtotime($this->date)); + } + + public function getSVGs(): array + { + return array_map(function ($file) { + $svg = file_get_contents(__DIR__ . '/../blog/' . $file); + + if (str_starts_with($svg, ']+>\s*/', '', $svg); + } + + return $svg; + }, $this->files); + } + + public static function get(string|int $id): Blog|null + { + $path = __DIR__ . "/../blog/$id.json"; + if (!file_exists($path)) + return null; + + try { + $json = json_decode(file_get_contents($path), true); + return new Blog($id, $json['title'], $json['date'], $json['files']); + } catch (Exception $e) { + return null; + } + } + + /** + * @return Blog[] + */ + public static function getAll() + { + $files = scandir(__DIR__ . '/../blog'); + $files = array_filter($files, function ($file) { + return str_ends_with($file, '.json'); + }); + + $ids = array_map(function ($file) { + return str_replace('.json', '', $file); + }, $files); + + $blogs = []; + + foreach ($ids as $id) { + $blog = Blog::get($id); + if ($blog !== null) + array_push($blogs, $blog); + } + + return $blogs; + } +} \ No newline at end of file