From: elektrischerwalfisch Date: Sat, 17 May 2025 15:12:12 +0000 (+0200) Subject: metadata as global variable X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=a9e921c554c4f8d2f3d16a7d36bf05a04c670ef3;p=flatmark metadata as global variable --- 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']) ?> + +