diff options
| author | root <root@caddy-256phi.local> | 2026-03-22 22:36:36 +0100 |
|---|---|---|
| committer | root <root@caddy-256phi.local> | 2026-03-22 22:36:36 +0100 |
| commit | f6d1edb5e928b260afc8363b184123e017783285 (patch) | |
| tree | 51ad4e06b71e333797d052e8088e0327d4ca17ba /blog/blog.php | |
| parent | 5c6f7592a7a81c98a8179ebbfa9546405ac1b576 (diff) | |
Initial commit of the original website
Diffstat (limited to 'blog/blog.php')
| -rw-r--r-- | blog/blog.php | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/blog/blog.php b/blog/blog.php new file mode 100644 index 0000000..f944c2e --- /dev/null +++ b/blog/blog.php @@ -0,0 +1,109 @@ +<?php +require 'Parsedown.php'; +$Parsedown = new Parsedown(); + +$postsDir = __DIR__ . '/posts/'; + +// Get requested post from URL (pretty slug) +$postParam = $_GET['post'] ?? null; + +if ($postParam) { + // Search for matching file by slug (ignoring date prefix) + $files = glob($postsDir . '*.md'); + $found = null; + foreach ($files as $file) { + $filename = pathinfo($file, PATHINFO_FILENAME); // e.g., 2026-03-05-why-i-use-nixos + $slug = preg_replace('/^\d{4}-\d{2}-\d{2}-/', '', $filename); // remove date prefix + if ($slug === $postParam) { + $found = $file; + break; + } + } + + if ($found) { + $markdown = file_get_contents($found); + + // Extract first heading line (# Title) as title + if (preg_match('/^# (.+)/m', $markdown, $matches)) { + $title = trim($matches[1]); + // Remove the first heading from content + $markdown = preg_replace('/^# .*/', '', $markdown, 1); + } else { + $title = "Blog Post"; + } + + $content = $Parsedown->text($markdown); + } else { + // Fallback to list if slug not found + $postParam = null; + } +} + +// If no valid post requested → show list of all posts +if (!$postParam) { + $files = array_reverse(glob($postsDir . '*.md')); // newest first + $content = "<ul class='blog-list'>"; + foreach ($files as $file) { + $filename = pathinfo($file, PATHINFO_FILENAME); + $slug = preg_replace('/^\d{4}-\d{2}-\d{2}-/', '', $filename); + + // Extract first # heading as title + $mdContent = file_get_contents($file); + if (preg_match('/^# (.+)/m', $mdContent, $matches)) { + $name = htmlspecialchars(trim($matches[1])); + } else { + $name = htmlspecialchars($slug); + } + + $content .= "<li><a href='/blog/$slug'>$name</a></li>"; + } + $content .= "</ul>"; + $title = "Blog"; +} +?> + +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="UTF-8"> +<title><?= htmlspecialchars($title) ?></title> +<link rel="stylesheet" href="../style.css"> +<style> +/* Blog-specific tweaks */ +.blog-content { + margin-top: 20px; + line-height: 1.6; +} +.blog-content h1, .blog-content h2, .blog-content h3 { + color: #ff00ff; + text-shadow: 0 0 5px #ff00ff, 0 0 15px rgba(255,0,255,0.6); +} +.blog-content p, .blog-content li { + color: #e0d6ff; +} +.blog-list li { + margin-bottom: 8px; +} +.blog-list a { + color: #00ffff; + text-decoration: none; +} +.blog-list a:hover { + text-shadow: 0 0 8px #00ffff; +} +</style> +</head> +<body> +<canvas id="bg"></canvas> +<div class="container"> + <h1><?= htmlspecialchars($title) ?></h1> + <div class="blog-content"> + <?= $content ?> + </div> + <footer> + <p>© 256phi | 2026 | <a href="/home">Home</a></p> + </footer> +</div> +<script type="module" src="../main.js"></script> +</body> +</html> |
