]> skyeroc.xyz Git - flatmark/commitdiff
change format for metadata
authorelektrischerwalfisch <mail@elektrischerwalfisch.de>
Sat, 17 May 2025 14:40:09 +0000 (16:40 +0200)
committerelektrischerwalfisch <mail@elektrischerwalfisch.de>
Sat, 17 May 2025 14:40:09 +0000 (16:40 +0200)
README.md
index.php
pages-de/404.md
pages-de/home.md
pages-en/404.md
pages-en/home.md

index b832b45a092452e9c49dcb752d2e4659b3e34a34..7bb01ea9433e7ee94360f0cf765c2704381d5bcc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -88,15 +88,17 @@ This file is the default startpoint of your website.
 Edit this file to change the error-message which is shown if a page is not found. 
 
 
-## Meta information
-Each Markdown page can include optional meta information using HTML comments at the top of the file.
+## Metadata
+Each Markdown page can include optional meta information at the top of the file (Format: YAML Font Matter).
 These values will be automatically extracted and used in the <head> section of the generated HTML page.
 
 Example Markdown file (about.md) with meta information:
 
-    <!-- title: About Us -->
-    <!-- description: Learn more about our mission and team. -->
-    <!-- robots: index, follow -->
+    ---
+    title: About Us
+    description: Learn more about our mission and team.
+    robots: index, follow
+    ---
 
     # Welcome to Our Company
 
index 23cc7da6c00519974e082d26015077eda66c50c4..363a55e9b675ba7904488c8c50f299509cbd973a 100644 (file)
--- a/index.php
+++ b/index.php
     // Read the content of the requested Markdown file into a string
         $markdown = file_get_contents($file);
             
-    // Set defaults for Titel and meta-values
-        $defaultPageTitle = ucfirst($page);
-        $defaultMetaDescription = "";
-        $defaultMetaRobots = "index, follow";
+    // Set defaults for page-titel and meta-values
+        $pageTitle = ucfirst($page);
+        $metaDescription = "";
+        $metaRobots = "index, follow";
 
-    // Overwrite defaults by extracting individual title, description and robots from the first lines of the markdown file
-        $pageTitle = $defaultPageTitle;
-        $metaDescription = $defaultMetaDescription;
-        $metaRobots = $defaultMetaRobots;
-        if (preg_match('/^<!--\s*title:(.*?)\s*-->$/m', $markdown, $matches)) {
-            $pageTitle = trim($matches[1]);
-        }
-        if (preg_match('/^<!--\s*description:(.*?)\s*-->$/m', $markdown, $matches)) {
-            $metaDescription = trim($matches[1]);
-        }
-        if (preg_match('/^<!--\s*robots:(.*?)\s*-->$/m', $markdown, $matches)) {
-            $metaRobots = trim($matches[1]);
+    // Detect and extract YAML Front Matter
+        if (preg_match('/^---\s*(.*?)\s*---\s*(.*)$/s', $markdown, $matches)) {
+            $yaml = $matches[1];
+            $markdown = $matches[2]; // Markdown content without front matter
+
+            // Parse YAML (basic parser without dependencies)
+            foreach (explode("\n", $yaml) as $line) {
+                if (preg_match('/^\s*(title|description|robots):\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;
+                }
+            }
         }
 
     // Load header and footer markdown files and convert to HTML
index bae7aaed1030c59cf1c08828b372b690f2fe6ae8..1079ac6b763870edb28645609916ae89f10c4842 100644 (file)
@@ -1,5 +1,8 @@
-<!-- title: 404 Error -->
-<!-- robots: noindex, nofollow -->
+---
+title: 404 Error
+description: Seite nicht gefunden
+robots: noindex, nofollow
+---
 
 # 404 Error
 
index db01a49e03ab2b61bc5fdcb76f6924aa38657109..f19a3925e97865a45975889be0e3717e1e393c70 100644 (file)
@@ -1,6 +1,8 @@
-<!-- title: flatMark - Ein minimalistischer Website-Generator auf Markdown-Basis -->
-<!-- description: Keine Datenbank nötig, kein unnötiger Ballast – nur Markdown und eine Prise PHP. Ideal für kleine Websites, Portfolios oder Dokumentationen. Die Inhalte werden direkt aus dem Dateisystem geladen. Einfach Markdown-Dateien bearbeiten und loslegen. -->
-<!-- robots: index, follow -->
+---
+title: flatMark - Ein minimalistischer Website-Generator auf Markdown-Basis
+description: Keine Datenbank nötig, kein unnötiger Ballast – nur Markdown und eine Prise PHP. Ideal für kleine Websites, Portfolios oder Dokumentationen. Die Inhalte werden direkt aus dem Dateisystem geladen. Einfach Markdown-Dateien bearbeiten und loslegen.
+robots: index, follow
+---
 
 {background color-02}{columns 33-66}
 {img-rounded}
index d319ea9369bb27073a824ccc8bfcf4ee1fa64851..6b22c2b8cf9600bbd818c3e7205a5a31fea004fd 100644 (file)
@@ -1,6 +1,8 @@
-<!-- title: 404 Not Found -->
-<!-- description: Page not found -->
-<!-- robots: noindex, nofollow -->
+---
+title: 404 Not Found
+description: Page not found
+robots: noindex, nofollow
+---
 
 # 404 Not Found
 
index 656afd60d0453d7443289b63e83b82338e966941..9e6ad7b298e9006c0ef8882aa2a2efd559180ada 100644 (file)
@@ -1,6 +1,8 @@
-<!-- title: flatMark - lightweight, flat-file Markdown-based website generator -->
-<!-- description: No database required, no overhead in sight — just Markdown and a sprinkle of PHP. Ideal for small websites, portfolios, or documentation, it delivers content directly from the filesystem. Just edit your Markdown files and go. -->
-<!-- robots: index, follow -->
+---
+title: flatMark - lightweight, flat-file Markdown-based website generator
+description: No database required, no overhead in sight — just Markdown and a sprinkle of PHP. Ideal for small websites, portfolios, or documentation, it delivers content directly from the filesystem. Just edit your Markdown files and go.
+robots: index, follow
+---
 
 {background color-02}{columns 33-66}
 {img-rounded}