diff --git a/flextype/Entries.php b/flextype/Entries.php index 9b7ba12d..8427e9e5 100755 --- a/flextype/Entries.php +++ b/flextype/Entries.php @@ -339,24 +339,6 @@ class Entries return Entries::$shortcode; } - /** - * Front matter parser - * - * $content = Entries::frontMatterParser($content); - * - * @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 entry * @@ -379,7 +361,7 @@ class Entries } else { // Create $entry_frontmatter and $entry_content - $entry = Entries::frontMatterParser($entry); + $entry = FrontmatterParser::parse($entry); $entry_frontmatter = $entry['matter']; $entry_content = $entry['body']; diff --git a/flextype/parsers/FrontmatterParser.php b/flextype/parsers/FrontmatterParser.php new file mode 100644 index 00000000..e139fdea --- /dev/null +++ b/flextype/parsers/FrontmatterParser.php @@ -0,0 +1,35 @@ + + * @link http://flextype.org + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flextype; + +class FrontmatterParser { + + /** + * Get [matter] and [body] from a content. + * PHP implementation of Jekyll Front Matter. + * + * $content = Entries::frontMatterParser($content); + * + * @param string $content Content to parse + * @access public + * @return array + */ + public static function parse(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))]; + } +}