From a9e921c554c4f8d2f3d16a7d36bf05a04c670ef3 Mon Sep 17 00:00:00 2001 From: elektrischerwalfisch Date: Sat, 17 May 2025 17:12:12 +0200 Subject: [PATCH] metadata as global variable --- index.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.php b/index.php index 363a55e..da550f8 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@ ucfirst($page), + 'description' => '', + 'robots' => 'index, follow', + ]; + + // Detect and extract metadata (YAML Front Matter) if (preg_match('/^---\s*(.*?)\s*---\s*(.*)$/s', $markdown, $matches)) { $yaml = $matches[1]; - $markdown = $matches[2]; // Markdown content without front matter + $markdown = $matches[2]; // Markdown content without metadata - // Parse YAML (basic parser without dependencies) + // Parse metadata manually (line by line) foreach (explode("\n", $yaml) as $line) { - if (preg_match('/^\s*(title|description|robots):\s*(.*)$/', $line, $meta)) { + if (preg_match('/^\s*([\w\-]+):\s*(.*)$/', $line, $meta)) { $key = trim($meta[1]); $value = trim($meta[2]); - if ($key === 'title') $pageTitle = $value; - if ($key === 'description') $metaDescription = $value; - if ($key === 'robots') $metaRobots = $value; + $pageMeta[$key] = $value; } } } @@ -90,9 +90,9 @@ - <?= htmlspecialchars($pageTitle) ?> - - + <?= htmlspecialchars($pageMeta['title']) ?> + + -- 2.47.3