added blog entry; added robots.txt and sitemap

This commit is contained in:
Ludwig Lehnert 2025-04-17 19:53:50 +02:00
parent 0343750b0b
commit a8a532106e
9 changed files with 68 additions and 3 deletions

View File

@ -5,6 +5,8 @@ RewriteEngine On
# -------------------------------------------
RewriteRule ^blog/([^/]+)/?$ /blog.php?id=$1 [L,QSA]
RewriteRule ^sitemap\.xml$ /sitemap.php
# ----------------------------------------------------
# 2. Rewrite /lib/* or /blog/* to /error.php?code=404
# with 404 response code (internal rewriting)

View File

@ -29,6 +29,8 @@ $rand_send_comment = mt_rand() % 5;
<base target="_blank">
<meta name="keywords" content="ludwig lehnert,blog,<?= join(",", $blog->keywords) ?>">
<title><?= $blog->title ?></title>
<style>

View File

@ -1,5 +1,9 @@
{
"title": "Test: First Blog Entry",
"keywords": [
"test",
"first blog entry"
],
"date": "2025-04-15",
"files": [
"0.svg"

12
www/blog/1.json Normal file
View File

@ -0,0 +1,12 @@
{
"title": "Thoughts about edge computation",
"keywords": [
"edge",
"edge computation",
"thoughts about edge computation"
],
"date": "2025-04-17",
"files": [
"1.svg"
]
}

1
www/blog/1.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 MiB

View File

@ -6,7 +6,7 @@ require_once __DIR__ . "/lib/_index.php";
$blogs = Blog::getAll();
usort($blogs, function ($a, $b) {
strtotime($b->date) - strtotime($a->date);
return strtotime($b->date) - strtotime($a->date);
});
?><!DOCTYPE html>

View File

@ -4,13 +4,15 @@ class Blog
{
public readonly string $id;
public readonly string $title;
public readonly array $keywords;
public readonly string $date;
public readonly array $files;
public function __construct(string $id, string $title, string $date, array $files)
public function __construct(string $id, string $title, array $keywords, string $date, array $files)
{
$this->id = $id;
$this->title = $title;
$this->keywords = $keywords;
$this->date = $date;
$this->files = $files;
}
@ -35,7 +37,7 @@ class Blog
try {
$json = json_decode(file_get_contents($path), true);
return new Blog($id, $json['title'], $json['date'], $json['files']);
return new Blog($id, $json['title'], $json['keywords'], $json['date'], $json['files']);
} catch (Exception $e) {
return null;
}

3
www/robots.txt Normal file
View File

@ -0,0 +1,3 @@
User-agent: *
Disallow: /assets/
Sitemap: https://lehnert.dev/sitemap.xml

39
www/sitemap.php Normal file
View File

@ -0,0 +1,39 @@
<?php
require_once __DIR__ . "/lib/_index.php";
$blogs = Blog::getAll();
echo '<?';
?>xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://lehnert.dev/</loc>
<lastmod>2025-04-17</lastmod>
<changefreq>monthly</changefreq>
<priority>1.0</priority>
</url>
<?php foreach ($blogs as $blog): ?>
<url>
<loc>https://lehnert.dev/blog/<?= $blog->id ?></loc>
<lastmod><?= $blog->date ?></lastmod>
<priority>0.8</priority>
</url>
<?php endforeach; ?>
<url>
<loc>https://lehnert.dev/imprint</loc>
<lastmod>2025-04-16</lastmod>
<changefreq>yearly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://lehnert.dev/privacy</loc>
<lastmod>2025-04-16</lastmod>
<changefreq>yearly</changefreq>
<priority>0.5</priority>
</url>
</urlset>