Fixed AntCMS matching the page header multiple times

This commit is contained in:
Belle Aerni 2023-01-11 14:07:39 -08:00
parent c513b01bad
commit 891012f6ff
4 changed files with 7 additions and 8 deletions

View file

@ -105,7 +105,7 @@ class AntCMS
$pageContent = file_get_contents($pagePath);
$pageHeaders = AntCMS::getPageHeaders($pageContent);
// Remove the AntCMS section from the content
$pageContent = preg_replace('/--AntCMS--.*--AntCMS--/s', '', $pageContent);
$pageContent = preg_replace('/\A--AntCMS--[^-]*--AntCMS--/sm', '', $pageContent);
$result = ['content' => $pageContent, 'title' => $pageHeaders['title'], 'author' => $pageHeaders['author'], 'description' => $pageHeaders['description'], 'keywords' => $pageHeaders['keywords']];
return $result;
} catch (\Exception $e) {
@ -178,10 +178,10 @@ class AntCMS
$AntKeywords = new AntKeywords();
// First get the AntCMS header and store it in the matches varible
preg_match('/--AntCMS--.*--AntCMS--/s', $pageContent, $matches);
preg_match('/\A--AntCMS--[^-]*--AntCMS--/sm', $pageContent, $matches);
// Then remove it from the page content so it doesn't cause issues if we try to generate the keywords
$pageContent = preg_replace('/--AntCMS--.*--AntCMS--/s', '', $pageContent);
$pageContent = str_replace($pageContent, '', $matches[0]);
$pageHeaders = [];
if ($matches) {

View file

@ -34,13 +34,12 @@ All content is stored in the `/Content` directory as `.md` files. Subfolders can
All pages must include a page header, this is used by AntCMS to get important page data. Please see this example for a page header:
(Note: the below header has a '-' removed from the end of the start and end header, this is to ensure the page is displayed correctly from within AntCMS.)
```
--AntCMS-
--AntCMS--
Title: An Example!
Author: The AntCMS Team
Description: Getting started with AntCMS.
--AntCMS-
--AntCMS--
```
When creating your page header, be sure to put a space after the ':', omitting it will cause issues when AntCMS tries to fetch the header info.

View file

@ -18,7 +18,7 @@
const output = document.getElementById("markdown-output");
function parseMarkdown() {
const inputValue = input.value.replace(/--AntCMS--.*--AntCMS--/s, "");
const inputValue = input.value.replace(/\A--AntCMS--[^-]*--AntCMS--/sm, "");
output.innerHTML = marked.parse(inputValue);
}

View file

@ -18,7 +18,7 @@
const output = document.getElementById("markdown-output");
function parseMarkdown() {
const inputValue = input.value.replace(/--AntCMS--.*--AntCMS--/s, "");
const inputValue = input.value.replace(/\A--AntCMS--[^-]*--AntCMS--/sm, "");
output.innerHTML = marked.parse(inputValue);
}