/** * Render Page object to string * * @param Page $page * @return string Rendered page */ public function render(Page $page) { if (!isset($page->title)) { throw new PageException('Page MUST have a `title` to be serialized'); } $delimiter = $this->delimiterRender . PHP_EOL; $delimiterSection = $this->sectionDelimiterRender . PHP_EOL; $metaArr = $page->getMeta(); if (isset($metaArr['slug'])) { // For flat files DB, the slug is the filename thus we don't need the slug unset($metaArr['slug']); } // Create the front matter $meta = $delimiter; $meta .= trim($this->metadataParser->encode($metaArr)); $meta .= PHP_EOL . $delimiter . PHP_EOL; // Add the content $content = trim($page->getContent()); // Add sections (if exist) if ($sections = $page->getSections()) { foreach ($sections as $section) { $metaSection = trim($this->metadataParser->encode($section->getMeta())); // $content .= PHP_EOL . PHP_EOL . $delimiterSection . $section->name . PHP_EOL . $delimiterSection; $content .= PHP_EOL . PHP_EOL . $delimiterSection . $section->name . PHP_EOL . $metaSection . PHP_EOL . $delimiterSection; $content .= trim($section->content) . PHP_EOL; } } return $meta . $content; }