Skip to content

Commit

Permalink
Improve performance by calculating. Fixes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Jun 6, 2018
1 parent 0570fb7 commit 4325008
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libs/Tree/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function getFrontMatter()

$frontMatter = new FrontMatter();

// Remove BOM if it's present
if (substr($content, 0, 3) == "\xef\xbb\xbf") {
$content = substr($content, 3);
}
Expand All @@ -44,7 +45,11 @@ protected function getFrontMatter()
*/
public function getContent()
{
return $this->getFrontMatter()->getContent();
if ($this->attributes === null) {
$this->parseAttributes();
}

return $this->content;
}

/**
Expand Down Expand Up @@ -115,6 +120,10 @@ protected function parseAttributes()

$document = $this->getFrontMatter();
$this->attributes = array_replace_recursive($this->attributes, $document->getData());

if (!$this->manuallySetContent) {
$this->content = $document->getContent();
}
}

public function setAttributes(array $attributes)
Expand Down

0 comments on commit 4325008

Please sign in to comment.