]> BookStack Code Mirror - bookstack/commitdiff
Implement the renderPages parameter 2227/head
authorVinnie Okada <redacted>
Fri, 14 Aug 2020 21:13:52 +0000 (15:13 -0600)
committerVinnie Okada <redacted>
Mon, 7 Sep 2020 15:05:51 +0000 (09:05 -0600)
Render page content when getTree() is called with a true $renderPages
argument.

app/Entities/Managers/BookContents.php

index 8b8d02c1dd0481539b17dcd2286e963e85581196..779a9292b404d169f9aa893ab29f892dd8613737 100644 (file)
@@ -41,7 +41,6 @@ class BookContents
 
     /**
      * Get the contents as a sorted collection tree.
-     * TODO - Support $renderPages option
      */
     public function getTree(bool $showDrafts = false, bool $renderPages = false): Collection
     {
@@ -60,8 +59,12 @@ class BookContents
             }
         });
 
-        $all->each(function (Entity $entity) {
+        $all->each(function (Entity $entity) use ($renderPages) {
             $entity->setRelation('book', $this->book);
+
+            if ($renderPages && get_class($entity) == 'BookStack\Entities\Page') {
+                $entity->html = (new PageContent($entity))->render();
+            }
         });
 
         return collect($chapters)->concat($lonePages)->sortBy($this->bookChildSortFunc());