From: elektrischerwalfisch Date: Sat, 12 Apr 2025 15:31:20 +0000 (+0200) Subject: rename file X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=ce02c8c3fda4763f2710976beac7df9e8579c182;p=flatmark rename file --- diff --git a/README.md b/README.md index f7de02e..e23865f 100644 --- a/README.md +++ b/README.md @@ -109,13 +109,13 @@ flatMark supports simple shortcodes for structured content. You can see all shor This content has a colored background. {/background} -These shortcodes are part of the theme and are all located in the file `/theme/shortcodes.php`. +These shortcodes are part of the theme and are all located in the file `/theme/functions.php`. You can edit this file to change existing shortcodes or add even more. An example-page with all shortcodes is provided with the installation: `/pages-en/shortcode-examples.md` ## Customization -All customizable parts of flatMark are located in the `theme/` folder. This includes the main stylesheet (`theme/css/style.css`), a JavaScript file for interactive behavior (`theme/js/presets.js`), and the `theme/shortcodes.php` file where custom shortcodes can be defined. You can freely modify these files to match your design and functionality needs. Additional assets like images, fonts, or scripts can also be placed in this folder to keep everything neatly organized in one place. +All customizable parts of flatMark are located in the `theme/` folder. This includes the main stylesheet (`theme/css/style.css`), a JavaScript file for interactive behavior (`theme/js/presets.js`), and the `theme/functions.php` file where custom shortcodes can be defined. You can freely modify these files to match your design and functionality needs. Additional assets like images, fonts, or scripts can also be placed in this folder to keep everything neatly organized in one place. ## flatMark as CMS diff --git a/index.php b/index.php index be614ea..23cc7da 100644 --- a/index.php +++ b/index.php @@ -13,8 +13,8 @@ ob_start(); // Include shortcode functions (if file exists) - if (file_exists('theme/shortcodes.php')) { - require 'theme/shortcodes.php'; + if (file_exists('theme/functions.php')) { + require 'theme/functions.php'; } // Include Parsedown @@ -72,7 +72,7 @@ $footerContent = $Parsedown->text($footerContent); } - // Apply theme/shortcodes.php before converting to HTML (if function exists) + // Apply theme/functions.php before converting to HTML (if function exists) if (function_exists('processShortcodes')) { $markdown = processShortcodes($markdown); } diff --git a/theme/functions.php b/theme/functions.php new file mode 100644 index 0000000..eb79be0 --- /dev/null +++ b/theme/functions.php @@ -0,0 +1,111 @@ +' . htmlspecialchars($matches[1]) . ''; + return $placeholder; + }, $markdown); + + // Shortcode: extras for header + $pattern = '/\{extras\}(.*?)\{\/extras\}/s'; + $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { + // Process Markdown inside + $extrasContent = $Parsedown->text($matches[1]); + return '
' . $extrasContent . '
'; + }, $markdown); + + // Shortcode: year (current year) + $pattern = '/\{year\}/s'; + $markdown = preg_replace_callback($pattern, function () { + return date("Y"); // Return current year + }, $markdown); + + // Shortcode: columns with optional classes + $pattern = '/\{columns(.*?)\}(.*?)\{\/columns\}/s'; + $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { + // Capture the additional class (if any exists) directly after {columns} + $colsAttributes = trim($matches[1]); // e.g., "50-50" from {background 50-50} + $colsContent = $matches[2]; // Capture the content inside {columns} ... {/columns} + + // Add prefix to the class + $colsPrefix = 'cols-'; // Define the prefix here + $colsClass = !empty($colsAttributes) ? $colsPrefix . $colsAttributes : ''; // Prefix added to class (e.g., cols-50-50) + + // Split the columns by {columns-seperator} + $cols = preg_split('/\{columns-seperator\}/', $colsContent); + + // Wrap each column in
+ $colHtml = ''; + foreach ($cols as $col) { + $colHtml .= '
' . $Parsedown->text(trim($col)) . '
'; + } + + // Wrap everything in a div and add class if available + return '
' . $colHtml . '
'; + }, $markdown); + + // Shortcode: background with optional class + $pattern = '/\{background(.*?)\}(.*?)\{\/background\}/s'; + $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { + // Capture the additional class (if any exists) directly after {background} + $bgAttributes = trim($matches[1]); // e.g., "color-01" from {background color-01} + $bgContent = $matches[2]; // Capture the content inside {background} ... {/background} + + // Add prefix to the class + $bgPrefix = 'bg-'; // Define the prefix here + $bgClass = !empty($bgAttributes) ? $bgPrefix . $bgAttributes : ''; // Prefix added to class (e.g., bg-color-01) + + // Convert the inner Markdown content + $bgHtml = $Parsedown->text($bgContent); + + // Wrap everything in a div and add class if available + return '
' . $bgHtml . '
'; + }, $markdown); + + // Shortcode: img rounded + $pattern = '/\{img-rounded\}(.*?)\{\/img-rounded\}/s'; + $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { + // Process Markdown + $imgRounded = $Parsedown->text($matches[1]); + return '
' . $imgRounded . '
'; + }, $markdown); + + // Shortcode: output readme-file + $pattern = '/\{readme\}/s'; + $markdown = preg_replace_callback($pattern, function () use ($Parsedown) { + $readmePath = __DIR__ . '/../README.md'; // path to root folder + if (file_exists($readmePath)) { + $readmeContent = file_get_contents($readmePath); + return '
' . $Parsedown->text($readmeContent) . '
'; + } else { + return '
README not found.
'; + } + }, $markdown); + + // Shortcode: code 2/2 - restore code blocks (so no shortcode inside was processed) + foreach ($codeBlocks as $placeholder => $codeBlock) { + $markdown = str_replace($placeholder, $codeBlock, $markdown); + } + + return $markdown; + + } + +?> + + diff --git a/theme/shortcodes.php b/theme/shortcodes.php deleted file mode 100644 index eb79be0..0000000 --- a/theme/shortcodes.php +++ /dev/null @@ -1,111 +0,0 @@ -' . htmlspecialchars($matches[1]) . ''; - return $placeholder; - }, $markdown); - - // Shortcode: extras for header - $pattern = '/\{extras\}(.*?)\{\/extras\}/s'; - $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { - // Process Markdown inside - $extrasContent = $Parsedown->text($matches[1]); - return '
' . $extrasContent . '
'; - }, $markdown); - - // Shortcode: year (current year) - $pattern = '/\{year\}/s'; - $markdown = preg_replace_callback($pattern, function () { - return date("Y"); // Return current year - }, $markdown); - - // Shortcode: columns with optional classes - $pattern = '/\{columns(.*?)\}(.*?)\{\/columns\}/s'; - $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { - // Capture the additional class (if any exists) directly after {columns} - $colsAttributes = trim($matches[1]); // e.g., "50-50" from {background 50-50} - $colsContent = $matches[2]; // Capture the content inside {columns} ... {/columns} - - // Add prefix to the class - $colsPrefix = 'cols-'; // Define the prefix here - $colsClass = !empty($colsAttributes) ? $colsPrefix . $colsAttributes : ''; // Prefix added to class (e.g., cols-50-50) - - // Split the columns by {columns-seperator} - $cols = preg_split('/\{columns-seperator\}/', $colsContent); - - // Wrap each column in
- $colHtml = ''; - foreach ($cols as $col) { - $colHtml .= '
' . $Parsedown->text(trim($col)) . '
'; - } - - // Wrap everything in a div and add class if available - return '
' . $colHtml . '
'; - }, $markdown); - - // Shortcode: background with optional class - $pattern = '/\{background(.*?)\}(.*?)\{\/background\}/s'; - $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { - // Capture the additional class (if any exists) directly after {background} - $bgAttributes = trim($matches[1]); // e.g., "color-01" from {background color-01} - $bgContent = $matches[2]; // Capture the content inside {background} ... {/background} - - // Add prefix to the class - $bgPrefix = 'bg-'; // Define the prefix here - $bgClass = !empty($bgAttributes) ? $bgPrefix . $bgAttributes : ''; // Prefix added to class (e.g., bg-color-01) - - // Convert the inner Markdown content - $bgHtml = $Parsedown->text($bgContent); - - // Wrap everything in a div and add class if available - return '
' . $bgHtml . '
'; - }, $markdown); - - // Shortcode: img rounded - $pattern = '/\{img-rounded\}(.*?)\{\/img-rounded\}/s'; - $markdown = preg_replace_callback($pattern, function ($matches) use ($Parsedown) { - // Process Markdown - $imgRounded = $Parsedown->text($matches[1]); - return '
' . $imgRounded . '
'; - }, $markdown); - - // Shortcode: output readme-file - $pattern = '/\{readme\}/s'; - $markdown = preg_replace_callback($pattern, function () use ($Parsedown) { - $readmePath = __DIR__ . '/../README.md'; // path to root folder - if (file_exists($readmePath)) { - $readmeContent = file_get_contents($readmePath); - return '
' . $Parsedown->text($readmeContent) . '
'; - } else { - return '
README not found.
'; - } - }, $markdown); - - // Shortcode: code 2/2 - restore code blocks (so no shortcode inside was processed) - foreach ($codeBlocks as $placeholder => $codeBlock) { - $markdown = str_replace($placeholder, $codeBlock, $markdown); - } - - return $markdown; - - } - -?> - -