Don't lower meta data unsolicited and flip meta headers array

Don't lower unregistered meta headers on the first level unsolicited (e.g. `SomeNotRegisteredKey: foobar` in the YAML Frontmatter should result in `['SomeNotRegisteredKey']`, not `['somenotregisteredkey']`). Furthermore, Pico no longer compares registered meta headers in a case-insensitive manner. However, you can now register multiple search strings that are used to find a registered meta header. This is achieved by flipping the meta headers array: Pico 2.0 uses the array key to search for a meta value and the array value to store the found meta value. Previously it was the other way round (what didn't make much sense...).
This commit is contained in:
Daniel Rudolf 2017-10-14 23:12:16 +02:00
parent 151908fbad
commit d8a649e6f7
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538
2 changed files with 17 additions and 25 deletions

View file

@ -1199,12 +1199,12 @@ class Pico
{
if ($this->metaHeaders === null) {
$this->metaHeaders = array(
'title' => 'Title',
'description' => 'Description',
'author' => 'Author',
'date' => 'Date',
'robots' => 'Robots',
'template' => 'Template'
'Title' => 'title',
'Description' => 'description',
'Author' => 'author',
'Date' => 'date',
'Robots' => 'robots',
'Template' => 'template'
);
$this->triggerEvent('onMetaHeaders', array(&$this->metaHeaders));
@ -1254,27 +1254,19 @@ class Pico
$pattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n"
. "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s";
if (preg_match($pattern, $rawContent, $rawMetaMatches) && isset($rawMetaMatches[3])) {
$meta = $this->getYamlParser()->parse($rawMetaMatches[3]);
$meta = $this->getYamlParser()->parse($rawMetaMatches[3]) ?: array();
$meta = is_array($meta) ? $meta : array('title' => $meta);
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);
if (isset($meta[$fieldName])) {
foreach ($headers as $name => $key) {
if (isset($meta[$name])) {
// rename field (e.g. remove whitespaces)
if ($fieldId != $fieldName) {
$meta[$fieldId] = $meta[$fieldName];
unset($meta[$fieldName]);
if ($key != $name) {
$meta[$key] = $meta[$name];
unset($meta[$name]);
}
} elseif (!isset($meta[$fieldId])) {
} elseif (!isset($meta[$key])) {
// guarantee array key existance
$meta[$fieldId] = '';
$meta[$key] = '';
}
}

View file

@ -403,8 +403,8 @@ class DummyPlugin extends AbstractPicoPlugin
*
* @see Pico::getMetaHeaders()
* @param string[] &$headers list of known meta header
* fields; the array value specifies the YAML key to search for, the
* array key is later used to access the found value
* fields; the array key specifies the YAML key to search for, the
* array value is later used to access the found value
* @return void
*/
public function onMetaHeaders(array &$headers)