From a6b63ca55169a4df71cf79ff272d58752c168edf Mon Sep 17 00:00:00 2001 From: ro Date: Mon, 18 Mar 2024 16:14:17 -0600 Subject: [PATCH] implemented render engine page rendering for tags, archives and markdown pages is now up and running and being exported to html when requested. currently it only works when saving a page, so now the settings page needs to be plugged in so those features can be activated and toggled through that UI error checking will probably be added in the near future just in case something unforeseen happens in the render process, resulting in the site erroring out. --- .../Controllers/Theming/ThemeController.php | 4 +- app/Providers/FipamoServiceProvider.php | 3 +- app/Repositories/PageRepository.php | 13 +- app/Services/RenderService.php | 122 ++++++++++++++---- .../themes/fipamo-default-v2/base.blade.php | 4 +- .../themes/fipamo-default-v2/tags.blade.php | 8 +- 6 files changed, 118 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/Theming/ThemeController.php b/app/Http/Controllers/Theming/ThemeController.php index 0d70c6c..ac2b7da 100644 --- a/app/Http/Controllers/Theming/ThemeController.php +++ b/app/Http/Controllers/Theming/ThemeController.php @@ -40,7 +40,7 @@ class ThemeController extends Controller $view == 'index' ? $template = $currentTheme . '.index' : $template = $currentTheme . '.page'; - $page = $this->pages->getById('09E5A362-BA31-4AE2-9DEE-C93DFBE005C3'); + $page = $this->pages->getById('532E2250-F8CB-4E87-9782-8AFBEE88DD5E'); $data = $this->sort->page($page); $pageData = [ "debug" => "true", @@ -67,7 +67,7 @@ class ThemeController extends Controller 'theme' => $currentTheme, // for theme kit 'title' => 'Pages Tagged as Tag', 'dynamicRender' => $data['info']['dynamicRender'], - 'tags' => $data['info']['tags'][3]['pages'], + '$pages' => $data['info']['tags'][3]['pages'], 'info' => $data['info'], 'menu' => $data['info']['menu'], 'media' => [ diff --git a/app/Providers/FipamoServiceProvider.php b/app/Providers/FipamoServiceProvider.php index 438bb73..d50622a 100644 --- a/app/Providers/FipamoServiceProvider.php +++ b/app/Providers/FipamoServiceProvider.php @@ -64,7 +64,8 @@ class FipamoServiceProvider extends ServiceProvider new ContentService(), new StringService(), ), - new SettingsService(new DocService()) + new SettingsService(new DocService()), + new ContentService(), ); }); diff --git a/app/Repositories/PageRepository.php b/app/Repositories/PageRepository.php index 17b1027..cf71f32 100644 --- a/app/Repositories/PageRepository.php +++ b/app/Repositories/PageRepository.php @@ -9,6 +9,7 @@ use App\Services\PaginateService; use App\Services\StringService; use App\Services\DocService; use App\Services\SortingService; +use App\Services\RenderService; use Carbon\Carbon; class PageRepository implements PageRepositoryInterface @@ -20,6 +21,7 @@ class PageRepository implements PageRepositoryInterface protected $strings; protected $docs; protected $sort; + protected $render; public function __construct( ContentService $contentService, @@ -28,6 +30,7 @@ class PageRepository implements PageRepositoryInterface StringService $stringService, DocService $docService, SortingService $sortingService, + RenderService $renderService ) { $this->content = $contentService; $this->settings = $settingsService; @@ -35,6 +38,7 @@ class PageRepository implements PageRepositoryInterface $this->strings = $stringService; $this->docs = $docService; $this->sort = $sortingService; + $this->render = $renderService; $this->pages = $this->content->loadAllPages(); } @@ -123,11 +127,9 @@ class PageRepository implements PageRepositoryInterface $this->settings->getGlobal()['renderOnSave'] == 'true' && $this->settings->getGlobal()['dynamicRender'] == 'false' ) { - //TODO: RENDER ENGINE STUFF - //$render = new Render(); - //$render->renderTags(); - //$render->renderArchive(); - //$render->renderPages(); + $this->render->tags(); + $this->render->archive(); + $this->render->pages(); $message = 'Filed edited and rendered. NOICE.'; } else { $message = 'File edited. Nice work'; @@ -139,7 +141,6 @@ class PageRepository implements PageRepositoryInterface //Settings::updateTags(); // if new page added, update current index in Settings file if ($task == 'create') { - //Settings::updateIndex(); $this->settings->updatePageIndex(); } diff --git a/app/Services/RenderService.php b/app/Services/RenderService.php index bd2a344..f0ea49b 100644 --- a/app/Services/RenderService.php +++ b/app/Services/RenderService.php @@ -2,51 +2,129 @@ namespace App\Services; +use Illuminate\Support\Facades\File; + class RenderService { private $sort; private $settings; + private $contents; private $pageInfo; private $menu; private $background; + private $theme; - public function __construct(SortingService $sortingService, SettingsService $settingsService) - { + public function __construct( + SortingService $sortingService, + SettingsService $settingsService, + ContentService $contentService + ) { $this->sort = $sortingService; $this->settings = $settingsService; + $this->contents = $contentService; + $this->theme = $this->settings->getGlobal()['theme']; } - public function tag() + public function archive() { - $list = $this->sort->tags(); - foreach ($list as $item) { - $template = 'tags.twig'; - $pageOptions = [ - 'title' => 'Pages Tagged as ' . $item['tag_name'], - 'background' => $this->pageInfo['image'], - 'tag_list' => $item['pages'], - 'info' => $this->pageInfo, - 'menu' => $this->menu, - 'media' => [['file' => $this->pageInfo['image'], 'type' => trim(pathinfo($this->pageInfo['image'], PATHINFO_EXTENSION))]], - ]; + $template = $this->theme . '.archive'; + $data = $this->sort->archive(); + $pageData = [ + 'theme' => $this->theme, // for theme kit + 'title' => 'Archives', + 'dynamicRender' => $data['info']['dynamicRender'], + 'archive' => $data['archive'], + 'info' => $data['info'], + 'menu' => $data['info']['menu'], + 'media' => [ + ['file' => $data['info']['image'], + 'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))] + ], + ]; + $location = '../public/archive.html'; + File::put( + $location, + view($template) + ->with($pageData) + ->render() + ); + } - $html = $this->twig->render($template, $pageOptions); + public function tags() + { + $data = $this->sort->tags(); + foreach ($data['tags'] as $item) { + //$template = 'tags.twig'; + $template = $this->theme . '.tags'; + $pageData = [ + 'theme' => $this->theme, // for theme kit + 'title' => 'Pages Tagged as ' . $item['tag_name'], + 'dynamicRender' => $data['info']['dynamicRender'], + 'info' => $data['info'], + 'menu' => $data['info']['menu'], + 'pages' => $item['pages'], + 'media' => [ + ['file' => $data['info']['image'], + 'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))] + ], + ]; $location = '../public/tags/' . $item['slug'] . '.html'; - //if tags folder doesn't exist, make it if (!is_dir('../public/tags')) { mkdir('../public/tags', 0755, true); - } else { } - if (!is_file($location)) { - file_put_contents($location, $html); + File::put( + $location, + view($template) + ->with($pageData) + ->render() + ); + } + } + + public function pages() + { + $pages = $this->contents->loadAllPages(); + foreach ($pages as $page) { + $template; + $page['layout'] == 'index' ? + $template = $this->theme . '.index' : + $template = $this->theme . '.page'; + + $data = $this->sort->page($page); + $pageData = [ + "theme" => $this->theme, + "status" => false, + "title" => $data['title'], + "meta" => $data['meta'], + "menu" => $data['menu'], + "info" => $data['info'], + "media" => $data['media'], + "files" => $data['files'], + "content" => $data['content'], + "recent" => $data['recent'], + "feature" => $data['featured'], + "tags" => $data['tags'], + "dynamicRender" => $data['dynamicRender'], + ]; + + if (str_contains($page['layout'], 'index')) { + $location = '../public/index.html'; } else { - ($new = fopen($location, 'w')) or die('Unable to open file!'); - fwrite($new, $html); - fclose($new); + // if page is a menu item, render the page on public root + if ($page['menu'] == 'true') { + $location = '../public/' . $page['slug'] . '.html'; + } else { + $dir = '../public/' . $page['path']; + if (!is_dir($dir)) { + mkdir($dir, 0755, true); + } + $location = '../public/' . $page['path'] . '/' . $page['slug'] . '.html'; + } } + File::put($location, view($template)->with($pageData)->render()); } } } diff --git a/content/themes/fipamo-default-v2/base.blade.php b/content/themes/fipamo-default-v2/base.blade.php index 067fce8..50e845e 100644 --- a/content/themes/fipamo-default-v2/base.blade.php +++ b/content/themes/fipamo-default-v2/base.blade.php @@ -42,7 +42,7 @@ @endif @endforeach @else - @if($media != '') + @if(isset($media[0]) && $media != '') @if($media[0]['type'] == "mp4")
diff --git a/content/themes/fipamo-default-v2/tags.blade.php b/content/themes/fipamo-default-v2/tags.blade.php index b8ee123..55318de 100644 --- a/content/themes/fipamo-default-v2/tags.blade.php +++ b/content/themes/fipamo-default-v2/tags.blade.php @@ -5,15 +5,15 @@ @section('main-content')

{{ $title }}

- @foreach($tags as $tag) + @foreach($pages as $page) @if(isset($dynamicRender)) @if($dynamicRender == 'true') - {{ $tag['title'] }}
+ {{ $page['title'] }}
@else - {{ $tag['title'] }}
+ {{ $page['title'] }}
@endif @else - {{ $tag['title'] }}
+ {{ $page['title'] }}
@endif @endforeach