added blogs to landing page
This commit is contained in:
parent
e6d10073b8
commit
5ebc391190
18
www/blog.php
18
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, '<?xml')) {
|
||||
$svg = preg_replace('/^\s*<\?xml[^>]+>\s*/', '', $svg);
|
||||
}
|
||||
$svgs = $blog->getSVGs();
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@ -26,7 +24,7 @@ if (str_starts_with($svg, '<?xml')) {
|
||||
|
||||
<base target="_blank">
|
||||
|
||||
<title>Blog</title>
|
||||
<title><?= $blog->title ?></title>
|
||||
|
||||
<style>
|
||||
html,
|
||||
@ -55,14 +53,16 @@ if (str_starts_with($svg, '<?xml')) {
|
||||
}
|
||||
|
||||
main>svg a:hover {
|
||||
opacity: 0.7;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<?= $svg ?>
|
||||
<?php foreach ($svgs as $svg): ?>
|
||||
<?= $svg ?>
|
||||
<?php endforeach; ?>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
100
www/index.php
100
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);
|
||||
});
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
@ -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";
|
||||
</script>
|
||||
|
||||
<main style="position: relative; z-index: 2;">
|
||||
<h1>Hey, I'm Ludwig 🚀</h1>
|
||||
<p>Welcome to my digital playground.</p>
|
||||
<div class="welcome">
|
||||
<h1>Hey, I'm Ludwig 🚀</h1>
|
||||
<p>Welcome to my digital playground.</p>
|
||||
|
||||
<div class="social-links">
|
||||
<a target="_blank" href="https://instagram.com/lehlud">
|
||||
<img src="/assets/instagram.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="https://linkedin.com/in/ludwig-lehnert">
|
||||
<img src="/assets/linkedin.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="mailto:info@lehnert.dev">
|
||||
<img src="/assets/email.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="https://gitea.cloud.lehnert.dev/explore/repos">
|
||||
<img src="/assets/git.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="https://github.com/lehlud">
|
||||
<img src="/assets/github.svg" alt="" width="25" />
|
||||
</a>
|
||||
<div class="social-links">
|
||||
<a target="_blank" href="https://instagram.com/lehlud">
|
||||
<img src="/assets/instagram.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="https://linkedin.com/in/ludwig-lehnert">
|
||||
<img src="/assets/linkedin.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="mailto:info@lehnert.dev">
|
||||
<img src="/assets/email.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="https://gitea.cloud.lehnert.dev/explore/repos">
|
||||
<img src="/assets/git.svg" alt="" width="25" />
|
||||
</a>
|
||||
<a target="_blank" href="https://github.com/lehlud">
|
||||
<img src="/assets/github.svg" alt="" width="25" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="legal-links">
|
||||
<a href="/imprint">Imprint</a>
|
||||
<a href="/privacy">Privacy Policy</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="legal-links">
|
||||
<a href="/imprint">Imprint</a>
|
||||
<a href="/privacy">Privacy Policy</a>
|
||||
<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>
|
||||
</body>
|
||||
|
@ -3,3 +3,4 @@
|
||||
require_once __DIR__ . '/style.php';
|
||||
require_once __DIR__ . '/stars.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