1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-18 02:41:27 +02:00

Content: new frontMatterParser() - added

This commit is contained in:
Awilum
2018-12-14 02:50:46 +03:00
parent 5314131013
commit 56db1ac568

View File

@@ -313,6 +313,22 @@ class Content
return Content::$shortcode;
}
/**
* Front matter parser
*
* @param string $content Content to parse
* @access public
* @return array
*/
public static function frontMatterParser(string $content) : array
{
$parts = preg_split('/^[\s\r\n]?---[\s\r\n]?$/sm', PHP_EOL.ltrim($content));
if (count($parts) < 3) return ['matter' => [], 'body' => $content];
return ['matter' => trim($parts[1]), 'body' => implode(PHP_EOL.'---'.PHP_EOL, array_slice($parts, 2))];
}
/**
* Process page
*
@@ -335,9 +351,9 @@ class Content
} else {
// Create $page_frontmatter and $page_content
$page = explode('---', $page, 3);
$page_frontmatter = $page[1];
$page_content = $page[2];
$page = Content::frontMatterParser($page);
$page_frontmatter = $page['matter'];
$page_content = $page['body'];
// Create empty $_page
$_page = [];