diff --git a/system/blueprints/pages/raw.yaml b/system/blueprints/pages/raw.yaml index 5d1d14908..d614a9ec6 100644 --- a/system/blueprints/pages/raw.yaml +++ b/system/blueprints/pages/raw.yaml @@ -33,3 +33,6 @@ form: @data-options: '\Grav\Common\Page\Pages::types' validate: required: true + + + diff --git a/system/src/Grav/Common/Filesystem/File/Markdown.php b/system/src/Grav/Common/Filesystem/File/Markdown.php index 10cc2d507..990628078 100644 --- a/system/src/Grav/Common/Filesystem/File/Markdown.php +++ b/system/src/Grav/Common/Filesystem/File/Markdown.php @@ -59,6 +59,25 @@ class Markdown extends General return $content['markdown']; } + /** + * Get/set frontmatter content. + * + * @param string $var + * + * @return string + */ + public function frontmatter($var = null) + { + $content = $this->content(); + + if ($var !== null) { + $content['frontmatter'] = (string) $var; + $this->content($content); + } + + return $content['frontmatter']; + } + /** * Check contents and make sure it is in correct format. * @@ -104,13 +123,18 @@ class Markdown extends General protected function decode($var) { $content = array(); + $content['header'] = array(); + $content['frontmatter'] = array(); // Normalize line endings to Unix style. $var = preg_replace("/(\r\n|\r)/", "\n", $var); // Parse header. preg_match("/---\n(.+?)\n---(\n\n|$)/uism", $var, $m); - $content['header'] = isset($m[1]) ? YamlParser::parse(preg_replace("/\n\t/", "\n ", $m[1])) : array(); + if (isset($m[1])) { + $content['frontmatter'] = preg_replace("/\n\t/", "\n ", $m[1]); + $content['header'] = YamlParser::parse($content['frontmatter']); + } // Strip header to get content. $content['markdown'] = trim(preg_replace("/---\n(.+?)\n---(\n\n|$)/uism", '', $var)); diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index e8c6076ab..108f05db7 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -54,6 +54,7 @@ class Page protected $modified; protected $id; protected $header; + protected $frontmatter; protected $content; protected $raw_content; protected $pagination; @@ -140,6 +141,14 @@ class Page return $file ? $file->raw() : ''; } + public function frontmatter($var = null) { + + if ($var) { + $this->frontmatter = $var; + } + return $this->frontmatter; + } + /** * Gets and Sets the header based on the YAML configuration at the top of the .md file * @@ -164,6 +173,7 @@ class Page $file = $this->file(); if ($file) { $this->raw_content = $file->markdown(); + $this->frontmatter = $file->frontmatter(); $this->header = (object) $file->header(); $var = true; @@ -254,6 +264,8 @@ class Page return Utils::truncateHTML($content, $size); } + + /** * Gets and Sets the content based on content portion of the .md file *