From 4325008a5fdce6f8a1d67adf3faade3b6b84cfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Wed, 6 Jun 2018 21:10:06 +0200 Subject: [PATCH] Improve performance by calculating. Fixes #55 --- libs/Tree/Content.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/Tree/Content.php b/libs/Tree/Content.php index 7ff7dce..1d9a128 100644 --- a/libs/Tree/Content.php +++ b/libs/Tree/Content.php @@ -32,6 +32,7 @@ class Content extends ContentAbstract $frontMatter = new FrontMatter(); + // Remove BOM if it's present if (substr($content, 0, 3) == "\xef\xbb\xbf") { $content = substr($content, 3); } @@ -44,7 +45,11 @@ class Content extends ContentAbstract */ public function getContent() { - return $this->getFrontMatter()->getContent(); + if ($this->attributes === null) { + $this->parseAttributes(); + } + + return $this->content; } /** @@ -115,6 +120,10 @@ class Content extends ContentAbstract $document = $this->getFrontMatter(); $this->attributes = array_replace_recursive($this->attributes, $document->getData()); + + if (!$this->manuallySetContent) { + $this->content = $document->getContent(); + } } public function setAttributes(array $attributes)