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 = "
";
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 .= "