added blogs to landing page
This commit is contained in:
parent
e6d10073b8
commit
5ebc391190
16
www/blog.php
16
www/blog.php
@ -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>
|
||||||
|
<?php foreach ($svgs as $svg): ?>
|
||||||
<?= $svg ?>
|
<?= $svg ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -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"
|
||||||
}
|
]
|
||||||
}
|
}
|
@ -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,6 +159,7 @@ require_once __DIR__ . "/lib/_index.php";
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main style="position: relative; z-index: 2;">
|
<main style="position: relative; z-index: 2;">
|
||||||
|
<div class="welcome">
|
||||||
<h1>Hey, I'm Ludwig 🚀</h1>
|
<h1>Hey, I'm Ludwig 🚀</h1>
|
||||||
<p>Welcome to my digital playground.</p>
|
<p>Welcome to my digital playground.</p>
|
||||||
|
|
||||||
@ -153,6 +185,16 @@ require_once __DIR__ . "/lib/_index.php";
|
|||||||
<a href="/imprint">Imprint</a>
|
<a href="/imprint">Imprint</a>
|
||||||
<a href="/privacy">Privacy Policy</a>
|
<a href="/privacy">Privacy Policy</a>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="blog-entries">
|
||||||
|
<?php foreach ($blogs as $blog): ?>
|
||||||
|
<div class="blog-entry">
|
||||||
|
<h2><a href="/blog/<?= $blog->id ?>"><?= $blog->title ?></a></h2>
|
||||||
|
<p><?= $blog->formatDate() ?></p>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -3,3 +3,4 @@
|
|||||||
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
74
www/lib/blog.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user