added blogs to landing page

This commit is contained in:
Ludwig Lehnert 2025-04-15 16:59:39 +02:00
parent e6d10073b8
commit 5ebc391190
5 changed files with 161 additions and 44 deletions

View File

@ -3,17 +3,15 @@
require_once __DIR__ . '/lib/_index.php'; require_once __DIR__ . '/lib/_index.php';
$id = (int) $_GET['id']; $id = (int) $_GET['id'];
$path = __DIR__ . "/blog/$id.svg";
if (!file_exists($path)) { $blog = Blog::get($id);
if ($blog === null) {
http_response_code(404); http_response_code(404);
require __DIR__ . '/404.php'; require __DIR__ . '/404.php';
exit; exit;
} }
$svg = file_get_contents($path); $svgs = $blog->getSVGs();
if (str_starts_with($svg, '<?xml')) {
$svg = preg_replace('/^\s*<\?xml[^>]+>\s*/', '', $svg);
}
?><!DOCTYPE html> ?><!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -26,7 +24,7 @@ if (str_starts_with($svg, '<?xml')) {
<base target="_blank"> <base target="_blank">
<title>Blog</title> <title><?= $blog->title ?></title>
<style> <style>
html, html,
@ -55,14 +53,16 @@ if (str_starts_with($svg, '<?xml')) {
} }
main>svg a:hover { main>svg a:hover {
opacity: 0.7; opacity: 0.6;
} }
</style> </style>
</head> </head>
<body> <body>
<main> <main>
<?= $svg ?> <?php foreach ($svgs as $svg): ?>
<?= $svg ?>
<?php endforeach; ?>
</main> </main>
</body> </body>

View File

@ -1,7 +1,7 @@
{ {
"links": { "title": "Test: First Blog Entry",
"google": "https://google.com", "date": "2025-04-15",
"handwritten.blog": "https://handwritten.blog", "files": [
"blog-lehnert.dev": "mailto:blog@lehnert.dev" "0.svg"
} ]
} }

View File

@ -4,6 +4,11 @@ require_once __DIR__ . "/lib/_index.php";
[$points, $edges, $sizes] = stars_random(); [$points, $edges, $sizes] = stars_random();
$blogs = Blog::getAll();
usort($blogs, function ($a, $b) {
strtotime($b->date) - strtotime($a->date);
});
?><!DOCTYPE html> ?><!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -32,17 +37,20 @@ require_once __DIR__ . "/lib/_index.php";
} }
main { main {
color: white;
font-family: "Inter", sans-serif;
pointer-events: none;
}
.welcome {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
min-height: 80vh; min-height: 80vh;
color: white;
font-family: "Inter", sans-serif;
text-align: center; text-align: center;
padding: 2rem; padding: 2rem;
pointer-events: none;
} }
h1 { h1 {
@ -95,16 +103,39 @@ require_once __DIR__ . "/lib/_index.php";
pointer-events: auto; pointer-events: auto;
} }
.legal-links a { a {
color: rgb(255, 255, 255); color: white;
cursor: pointer;
transition: background 0.3s ease;
} }
.legal-links a:hover { a:hover {
opacity: 0.8; 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 { @keyframes glow {
from { from {
@ -128,30 +159,41 @@ require_once __DIR__ . "/lib/_index.php";
</script> </script>
<main style="position: relative; z-index: 2;"> <main style="position: relative; z-index: 2;">
<h1>Hey, I'm Ludwig 🚀</h1> <div class="welcome">
<p>Welcome to my digital playground.</p> <h1>Hey, I'm Ludwig 🚀</h1>
<p>Welcome to my digital playground.</p>
<div class="social-links"> <div class="social-links">
<a target="_blank" href="https://instagram.com/lehlud"> <a target="_blank" href="https://instagram.com/lehlud">
<img src="/assets/instagram.svg" alt="" width="25" /> <img src="/assets/instagram.svg" alt="" width="25" />
</a> </a>
<a target="_blank" href="https://linkedin.com/in/ludwig-lehnert"> <a target="_blank" href="https://linkedin.com/in/ludwig-lehnert">
<img src="/assets/linkedin.svg" alt="" width="25" /> <img src="/assets/linkedin.svg" alt="" width="25" />
</a> </a>
<a target="_blank" href="mailto:info@lehnert.dev"> <a target="_blank" href="mailto:info@lehnert.dev">
<img src="/assets/email.svg" alt="" width="25" /> <img src="/assets/email.svg" alt="" width="25" />
</a> </a>
<a target="_blank" href="https://gitea.cloud.lehnert.dev/explore/repos"> <a target="_blank" href="https://gitea.cloud.lehnert.dev/explore/repos">
<img src="/assets/git.svg" alt="" width="25" /> <img src="/assets/git.svg" alt="" width="25" />
</a> </a>
<a target="_blank" href="https://github.com/lehlud"> <a target="_blank" href="https://github.com/lehlud">
<img src="/assets/github.svg" alt="" width="25" /> <img src="/assets/github.svg" alt="" width="25" />
</a> </a>
</div>
<div class="legal-links">
<a href="/imprint">Imprint</a>
<a href="/privacy">Privacy Policy</a>
</div>
</div> </div>
<div class="legal-links"> <div class="blog-entries">
<a href="/imprint">Imprint</a> <?php foreach ($blogs as $blog): ?>
<a href="/privacy">Privacy Policy</a> <div class="blog-entry">
<h2><a href="/blog/<?= $blog->id ?>"><?= $blog->title ?></a></h2>
<p><?= $blog->formatDate() ?></p>
</div>
<?php endforeach; ?>
</div> </div>
</main> </main>
</body> </body>

View File

@ -2,4 +2,5 @@
require_once __DIR__ . '/style.php'; require_once __DIR__ . '/style.php';
require_once __DIR__ . '/stars.php'; require_once __DIR__ . '/stars.php';
require_once __DIR__ . '/fill.php'; require_once __DIR__ . '/fill.php';
require_once __DIR__ . '/blog.php';

74
www/lib/blog.php Normal file
View File

@ -0,0 +1,74 @@
<?php
class Blog
{
public readonly string $id;
public readonly string $title;
public readonly string $date;
public readonly array $files;
public function __construct(string $id, string $title, string $date, array $files)
{
$this->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, '<?xml')) {
$svg = preg_replace('/^\s*<\?xml[^>]+>\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;
}
}