From: elektrischerwalfisch Date: Sat, 17 May 2025 14:40:09 +0000 (+0200) Subject: change format for metadata X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=c0a15c0c9bef1f53c61f70e928aea8e2e11f19d3;p=flatmark change format for metadata --- diff --git a/README.md b/README.md index b832b45..7bb01ea 100644 --- 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 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 + --- # Welcome to Our Company diff --git a/index.php b/index.php index 23cc7da..363a55e 100644 --- a/index.php +++ b/index.php @@ -31,23 +31,26 @@ // 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('/^$/m', $markdown, $matches)) { - $pageTitle = trim($matches[1]); - } - if (preg_match('/^$/m', $markdown, $matches)) { - $metaDescription = trim($matches[1]); - } - if (preg_match('/^$/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 diff --git a/pages-de/404.md b/pages-de/404.md index bae7aae..1079ac6 100644 --- a/pages-de/404.md +++ b/pages-de/404.md @@ -1,5 +1,8 @@ - - +--- +title: 404 Error +description: Seite nicht gefunden +robots: noindex, nofollow +--- # 404 Error diff --git a/pages-de/home.md b/pages-de/home.md index db01a49..f19a392 100644 --- a/pages-de/home.md +++ b/pages-de/home.md @@ -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 +--- {background color-02}{columns 33-66} {img-rounded} diff --git a/pages-en/404.md b/pages-en/404.md index d319ea9..6b22c2b 100644 --- a/pages-en/404.md +++ b/pages-en/404.md @@ -1,6 +1,8 @@ - - - +--- +title: 404 Not Found +description: Page not found +robots: noindex, nofollow +--- # 404 Not Found diff --git a/pages-en/home.md b/pages-en/home.md index 656afd6..9e6ad7b 100644 --- a/pages-en/home.md +++ b/pages-en/home.md @@ -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 +--- {background color-02}{columns 33-66} {img-rounded}