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

Commit

Permalink
Work with content.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Mar 20, 2017
1 parent d82c373 commit f363b10
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Step/LoadContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace PHPoole\Step;

use PHPoole\Exception\Exception;
use PHPoole\Util;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

Expand Down Expand Up @@ -49,6 +50,7 @@ public function internalProcess()
/* @var $file SplFileInfo */
foreach ($files as $file) {
$index = $file->getRelativePathname();
<<<<<<< Updated upstream
if (array_key_exists('frontmatter', $data)) {
$fmProperties = $this->parse(
$file->getContents(),
Expand All @@ -59,16 +61,35 @@ public function internalProcess()
$properties[$index]['id'] = $index;
$properties[$index]['format'] = $format;
$properties[$index]['lastmodified'] = $file->getMTime();
=======

$content[$index]['id'] = $index;
$content[$index]['filepath'] = $index;
$content[$index]['path'] = Util::urlize(trim($index, '.'.$format));

$content[$index]['format'] = $format;
$content[$index]['lastmodified'] = $file->getMTime();

// front matter?
if (isset($data['frontmatter'])) {
$content[$index] = array_merge($content[$index], $this->parseFM(
$file->getContents(),
$this->phpoole->getConfig()->get('content.frontmatter.'.$data['frontmatter'].'.parser')
)) ;
}
>>>>>>> Stashed changes
}
}

// DEBUG
//echo 'content:'.PHP_EOL;
//print_r($content);

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

/**
* Parse the contents of a file.
* Parse front matter of a file.
*
* Example:
* ```
Expand All @@ -84,7 +105,7 @@ public function internalProcess()
*
* @return array
*/
public function parse($content, $fmParser)
public function parseFM($content, $fmParser)
{
$properties = [];

Expand All @@ -96,15 +117,15 @@ public function parse($content, $fmParser)
);
// if not front matter, set 'content' property only
if (!$matches) {
$properties['raw'] = $content;
$properties['content'] = $content;

return $properties;
}
// parse front matter
/* @var $parser \PHPoole\Parser\ParserInterface */
$parser = new $fmParser();
$properties = $parser->parse(trim($matches[1]));
$properties['raw'] = trim($matches[2]);
$properties['content'] = trim($matches[2]);

return $properties;
}
Expand Down

0 comments on commit f363b10

Please sign in to comment.