From fb4bdfe1fc4301e5689930cbafbd8f93d6214945 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Fri, 15 Jul 2016 03:13:58 +0200 Subject: [PATCH] Fix Pico::parseFileMeta() for non-YAML 1-liners \Symfony\Component\Yaml\Parser::parse() returns the unchanged value when a 1-liner string which is no valid YAML is passed. Assume this string to be the page title. Thus the following page will work now: ``` --- This is the title --- # Example page {{ meta.title }} is going to be "This is the title" - or "%meta.title%" == "This is the title". ``` --- CHANGELOG.md | 1 + lib/Pico.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baa11a3..223b536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Released: - ``` * [New] Add Pico's social icons to default theme +* [Fixed] Fix handling of non-YAML 1-line front matters ``` ### Version 1.0.3 diff --git a/lib/Pico.php b/lib/Pico.php index dab794a..d88568a 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -777,7 +777,14 @@ class Pico if (preg_match($pattern, $rawContent, $rawMetaMatches) && isset($rawMetaMatches[3])) { $yamlParser = new \Symfony\Component\Yaml\Parser(); $meta = $yamlParser->parse($rawMetaMatches[3]); - $meta = ($meta !== null) ? array_change_key_case($meta, CASE_LOWER) : array(); + + if ($meta !== null) { + // the parser may return a string for non-YAML 1-liners + // assume that this string is the page title + $meta = is_array($meta) ? array_change_key_case($meta, CASE_LOWER) : array('title' => $meta); + } else { + $meta = array(); + } foreach ($headers as $fieldId => $fieldName) { $fieldName = strtolower($fieldName);