From 041bf98d8b20b6874cfd8c2edc7fa43bb88d2844 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 17 Apr 2022 14:25:17 +0200 Subject: [PATCH] Parse the documentation pages using the fileservice --- src/DocumentationPageParser.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/DocumentationPageParser.php b/src/DocumentationPageParser.php index b9c3e061..411aa8bf 100644 --- a/src/DocumentationPageParser.php +++ b/src/DocumentationPageParser.php @@ -3,23 +3,30 @@ namespace Hyde\Framework; use Hyde\Framework\Models\DocumentationPage; +use Hyde\Framework\Services\MarkdownFileService; class DocumentationPageParser extends AbstractPageParser { protected string $pageModel = DocumentationPage::class; protected string $slug; - public string $body; public string $title; + public string $body; public function execute(): void { - $stream = file_get_contents(Hyde::path("_docs/$this->slug.md")); - - $this->title = $this->findTitleTag($stream) ?? - Hyde::titleFromSlug($this->slug); + $document = (new MarkdownFileService( + Hyde::path("_docs/$this->slug.md") + ))->get(); + + if (isset($document->matter['title'])) { + $this->title = $document->matter['title']; + } else { + $this->title = $this->findTitleTag($document->body) ?? + Hyde::titleFromSlug($this->slug); + } - $this->body = $stream; + $this->body = $document->body; } /**