Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Commit

Permalink
Refactoring Load content (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Jan 7, 2017
1 parent 30e9253 commit 93e999d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Step/LoadContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LoadContent extends AbstractStep
{
// pattern of a file with a front matter
// https://regex101.com/r/xH7cL3/1
const PATTERN = '^\s*(?:<!--|---|\+++){1}[\n\r\s]*(.*?)[\n\r\s]*(?:-->|---|\+++){1}[\s\n\r]*(.*)$';
const FM_PATTERN = '^\s*(?:<!--|---|\+++){1}[\n\r\s]*(.*?)[\n\r\s]*(?:-->|---|\+++){1}[\s\n\r]*(.*)$';

/**
* {@inheritdoc}
Expand All @@ -39,7 +39,7 @@ public function init()
*/
public function internalProcess()
{
$content = [];
$properties = [];
// collects files in each supported format
foreach ($this->phpoole->getConfig()->get('content.format') as $format => $data) {
$files = Finder::create()
Expand All @@ -49,20 +49,22 @@ public function internalProcess()
/* @var $file SplFileInfo */
foreach ($files as $file) {
$index = $file->getRelativePathname();
$properties = $this->parse(
$file->getContents(),
$this->phpoole->getConfig()->get('content.frontmatter.'.$data['frontmatter'].'.parser')
);
$content[$index] = $properties;
$content[$index]['id'] = $index;
$content[$index]['format'] = $format;
$content[$index]['lastmodified'] = $file->getMTime();
if (array_key_exists('frontmatter', $data)) {
$fmProperties = $this->parse(
$file->getContents(),
$this->phpoole->getConfig()->get('content.frontmatter.'.$data['frontmatter'].'.parser')
);
$properties[$index] = $fmProperties;
}
$properties[$index]['id'] = $index;
$properties[$index]['format'] = $format;
$properties[$index]['lastmodified'] = $file->getMTime();
}
}

//print_r($content);

$this->phpoole->setContent($content);
$this->phpoole->setContent($properties);
}

/**
Expand All @@ -88,7 +90,7 @@ public function parse($content, $fmParser)

// parse front matter
preg_match(
'/'.self::PATTERN.'/s',
'/'.self::FM_PATTERN.'/s',
$content,
$matches
);
Expand Down

0 comments on commit 93e999d

Please sign in to comment.