]> skyeroc.xyz Git - flatmark/commitdiff
metadata as global variable
authorelektrischerwalfisch <mail@elektrischerwalfisch.de>
Sat, 17 May 2025 15:12:12 +0000 (17:12 +0200)
committerelektrischerwalfisch <mail@elektrischerwalfisch.de>
Sat, 17 May 2025 15:12:12 +0000 (17:12 +0200)
index.php

index 363a55e9b675ba7904488c8c50f299509cbd973a..da550f85dba0c82c59be55b354dc1db184e64189 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,7 +1,7 @@
 <?php
 /**
  * Project: flatMark
- * Version: 1.0
+ * Version: 1.1.0
  * 
  * Project URI: https://github.com/elektrischerwalfisch/flatmark
  * Author: elektrischerwalfisch
 
     // Read the content of the requested Markdown file into a string
         $markdown = file_get_contents($file);
-            
-    // Set defaults for page-titel and meta-values
-        $pageTitle = ucfirst($page);
-        $metaDescription = "";
-        $metaRobots = "index, follow";
 
-    // Detect and extract YAML Front Matter
+    // Set default metadata values in global scope
+        $pageMeta = [
+            'title' => 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 @@
     <head>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
-        <title><?= htmlspecialchars($pageTitle) ?></title>
-        <meta name="description" content="<?= htmlspecialchars($metaDescription) ?>">
-        <meta name="robots" content="<?= htmlspecialchars($metaRobots) ?>">
+        <title><?= htmlspecialchars($pageMeta['title']) ?></title>
+        <meta name="description" content="<?= htmlspecialchars($pageMeta['description']) ?>">
+        <meta name="robots" content="<?= htmlspecialchars($pageMeta['robots']) ?>">
         <link rel="stylesheet" href="/theme/css/style.css">
     </head>
     <body>