From 1f62e6f816d1090c42a99b4fdd76fd8d13c63116 Mon Sep 17 00:00:00 2001 From: ro Date: Thu, 28 Mar 2024 16:42:37 -0600 Subject: [PATCH] reworked sorting service class decided to keep the sorting service class as is and remix how it works to return data objects rather than just settings information to render pages. the overall size of the class is still large but now there are some opportunites to move around some methodolgy to reduce it. also made the necessary changes in the render service class and the theme controller to use the new methodology --- .../Controllers/Theming/ThemeController.php | 48 +------ app/Repositories/PageRepository.php | 6 +- app/Services/RenderService.php | 44 +------ app/Services/SortingService.php | 123 +++++++++--------- .../themes/fipamo-default-v2/base.blade.php | 7 +- 5 files changed, 78 insertions(+), 150 deletions(-) diff --git a/app/Http/Controllers/Theming/ThemeController.php b/app/Http/Controllers/Theming/ThemeController.php index ac2b7da..c35049d 100644 --- a/app/Http/Controllers/Theming/ThemeController.php +++ b/app/Http/Controllers/Theming/ThemeController.php @@ -41,58 +41,16 @@ class ThemeController extends Controller $template = $currentTheme . '.index' : $template = $currentTheme . '.page'; $page = $this->pages->getById('532E2250-F8CB-4E87-9782-8AFBEE88DD5E'); - $data = $this->sort->page($page); - $pageData = [ - "debug" => "true", - "theme" => $currentTheme, - "status" => $this->auth::status(), - "title" => "THEME PAGE", - "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'], - ]; + $pageData = $this->sort->page($page); break; case "tags": $template = $currentTheme . '.tags'; - $data = $this->sort->tags(); - $pageData = [ - 'debug' => true, // for theme kit - 'theme' => $currentTheme, // for theme kit - 'title' => 'Pages Tagged as Tag', - 'dynamicRender' => $data['info']['dynamicRender'], - '$pages' => $data['info']['tags'][3]['pages'], - 'info' => $data['info'], - 'menu' => $data['info']['menu'], - 'media' => [ - ['file' => $data['info']['image'], - 'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))] - ], - ]; + $pageData = $this->sort->tags(); break; case "archives": case "archive": $template = $currentTheme . '.archive'; - $data = $this->sort->archive(); - $pageData = [ - 'debug' => true, // for theme kit - 'theme' => $currentTheme, // 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))] - ], - ]; + $pageData = $this->sort->archive(); break; } if ($this->auth::status()) { diff --git a/app/Repositories/PageRepository.php b/app/Repositories/PageRepository.php index a7678f9..7f96f3a 100644 --- a/app/Repositories/PageRepository.php +++ b/app/Repositories/PageRepository.php @@ -6,7 +6,6 @@ use App\Interfaces\PageRepositoryInterface; use App\Services\SettingsService; use App\Services\ContentService; use App\Services\PaginateService; -use App\Services\StringService; use App\Services\DocService; use App\Services\SortingService; use App\Services\RenderService; @@ -18,7 +17,6 @@ class PageRepository implements PageRepositoryInterface protected $setttings; protected $paginate; protected $pages; - protected $strings; protected $docs; protected $sort; protected $render; @@ -27,7 +25,6 @@ class PageRepository implements PageRepositoryInterface ContentService $contentService, SettingsService $settingsService, PaginateService $paginateService, - StringService $stringService, DocService $docService, SortingService $sortingService, RenderService $renderService @@ -35,7 +32,6 @@ class PageRepository implements PageRepositoryInterface $this->content = $contentService; $this->settings = $settingsService; $this->paginate = $paginateService; - $this->strings = $stringService; $this->docs = $docService; $this->sort = $sortingService; $this->render = $renderService; @@ -103,7 +99,7 @@ class PageRepository implements PageRepositoryInterface // grab current index from settings and update $id = $task != 'create' ? $body->id : $this->settings->getSettings()['library_stats']['current_index']; - $uuid = $task != 'create' ? $body->uuid : $this->strings::createUUID(); + $uuid = $task != 'create' ? $body->uuid : createUUID(); //set variables post body for saving $body->id = $id; $body->uuid = $uuid; diff --git a/app/Services/RenderService.php b/app/Services/RenderService.php index 63fd4dd..e44d74a 100644 --- a/app/Services/RenderService.php +++ b/app/Services/RenderService.php @@ -57,20 +57,8 @@ class RenderService public function archive() { $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'; + $pageData = $this->sort->archive(false); + $location = '../public/archives.html'; File::put( $location, view($template) @@ -81,21 +69,18 @@ class RenderService public function tags() { - $data = $this->sort->tags(); + $data = $this->sort->tags(false); 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'], + 'dynamicRender' => $data['dynamicRender'], 'info' => $data['info'], - 'menu' => $data['info']['menu'], + 'menu' => $data['menu'], 'pages' => $item['pages'], - 'media' => [ - ['file' => $data['info']['image'], - 'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))] - ], + 'media' => $data['media'], ]; $location = '../public/tags/' . $item['slug'] . '.html'; @@ -122,22 +107,7 @@ class RenderService $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'], - ]; + $pageData = $this->sort->page($page, false); if (str_contains($page['layout'], 'index')) { $location = '../public/index.html'; diff --git a/app/Services/SortingService.php b/app/Services/SortingService.php index c0a6d09..1c102af 100644 --- a/app/Services/SortingService.php +++ b/app/Services/SortingService.php @@ -14,6 +14,7 @@ class SortingService private $settings; private $contents; private $themes; + private $info = []; public function __construct( SettingsService $settingsService, @@ -23,9 +24,22 @@ class SortingService $this->settings = $settingsService; $this->contents = $contentService; $this->themes = $themeService; + $global = $this->settings->getGlobal(); + $this->info = [ + 'keywords' => isset($global['keywords']) + ? $global['keywords'] + : 'fipamo, blog, jamstack, php, markdown, js', + 'menu' => $this->settings->getMenu(), + 'tags' => $this->settings->getTags(), + 'description' => $global['descriptions'], + 'image' => $global['base_url'] . $global['background'], + 'baseURL' => $global['base_url'], + 'dynamicRender' => $global['dynamicRender'], + 'theme' => $global['theme'], + ]; } - public function tags() + public function tags($debug = true) { $pages = $this->contents->loadAllPages(); foreach ($pages as $page) { @@ -44,24 +58,23 @@ class SortingService } } } - $global = $this->settings->getGlobal(); $tagData = []; - $pageInfo = [ - 'keywords' => isset($global['keywords']) - ? $global['keywords'] - : 'fipamo, blog, jamstack, php, markdown, js', - 'menu' => $this->settings->getMenu(), - 'tags' => $this->settings->getTags(), - 'description' => $global['descriptions'], - 'image' => $global['base_url'] . $global['background'], - 'baseURL' => $global['base_url'], - 'dynamicRender' => $global['dynamicRender'], - ]; $tagData = [ - 'tags' => $this->p_tags, - 'info' => $pageInfo, + 'debug' => $debug, // for theme kit + 'tags' => $this->p_tags, + 'theme' => $this->info['theme'], // for theme kit + 'title' => 'Pages Tagged as Tag', + 'dynamicRender' => $this->info['dynamicRender'], + 'pages' => $this->settings->getTags()[3]['pages'], + 'info' => $this->info, + 'menu' => $this->settings->getMenu(), + 'media' => [ + ['file' => $this->info['image'], + 'type' => trim(pathinfo($this->info['image'], PATHINFO_EXTENSION))] + ] ]; + return $tagData; } @@ -84,18 +97,15 @@ class SortingService return $tagged; } - public function archive() + public function archive($debug = true) { $pages = $this->contents->loadAllPages(); $years = []; $archive = []; foreach ($pages as $page) { - // $year = date("Y", date($page["rawCreated"])); $date = explode('/', $page['path']); - // echo $page["title"] . " : " . $year . "\n"; if (!find($years, ['year' => trim($date[0])])) { $findPages = filter($pages, ['createdYear' => trim($date[0])]); - // var_dump($findPages); array_push( $years, [ @@ -108,7 +118,6 @@ class SortingService foreach ($years as $year) { $sorted = []; $filtered = filter($pages, ['createdYear' => $year['year']]); - foreach ($filtered as $obj) { $month = date('m', date($obj['rawCreated'])); if (!find($sorted, ['month' => $month])) { @@ -134,41 +143,29 @@ class SortingService 'year_data' => $sorted, ]); } - $global = $this->settings->getGlobal(); $archive_data = []; - $pageInfo = [ - 'keywords' => isset($global['keywords']) - ? $global['keywords'] - : 'fipamo, blog, jamstack, php, markdown, js', - 'menu' => $this->settings->getMenu(), - 'tags' => $this->settings->getTags(), - 'description' => $global['descriptions'], - 'image' => $global['base_url'] . $global['background'], - 'baseURL' => $global['base_url'], - 'dynamicRender' => $global['dynamicRender'], - ]; + $archiveData = [ - 'archive' => $this->p_archive, - 'info' => $pageInfo, + 'debug' => $debug, // for theme kit + 'theme' => $this->info['theme'], // for theme kit + 'title' => 'Archives', + 'dynamicRender' => $this->info['dynamicRender'], + 'archive' => $this->p_archive, + 'info' => $this->info, + 'menu' => $this->settings->getMenu(), + 'media' => [ + ['file' => $this->info['image'], + 'type' => trim(pathinfo($this->info['image'], PATHINFO_EXTENSION))] + ], ]; return $archiveData; } - public function page($page) + public function page($page, $debug = true) { - $global = $this->settings->getGlobal(); $pageOptions = []; - - $pageInfo = [ - 'keywords' => isset($global['keywords']) - ? $global['keywords'] - : 'fipamo, blog, jamstack, php, markdown, js', - 'description' => $global['descriptions'], - 'image' => $global['base_url'] . $global['background'], - 'baseURL' => $global['base_url'], - ]; - $tags = []; + $tags = []; if (isset($page['tags'])) { $taglist = explode(',', $page['tags']); foreach ($taglist as $tag) { @@ -194,8 +191,8 @@ class SortingService $ext = pathinfo($item, PATHINFO_EXTENSION); if ($ext != 'mp4' && !$set) { - $pageInfo['image'] = $pageInfo['baseURL'] . $item; - $set = true; + $this->info['image'] = $this->info['baseURL'] . $item; + $set = true; } } } @@ -231,21 +228,23 @@ class SortingService } } - $pageOptions = [ - 'title' => $page['title'], - 'background' => $page['feature'], - 'content' => $page['html'], - 'meta' => $meta, - 'recent' => $recent, - 'featured' => $featured, - 'info' => $pageInfo, - 'menu' => $this->settings->getMenu(), - 'dynamicRender' => $global['dynamicRender'], - 'media' => $page['media'], - 'files' => $page['docs'], - 'tags' => $meta['tags'], + $pageData = [ + "debug" => $debug, + "theme" => $this->info['theme'], + "status" => session('member') != null ? true : false, + "title" => $page['title'], + "meta" => $meta, + "menu" => $this->settings->getMenu(), + "info" => $this->info, + "media" => $page['media'], + "files" => $page['docs'], + "content" => $page['html'], + "recent" => $recent, + "feature" => $featured, + "tags" => $meta['tags'], + "dynamicRender" => $this->info['dynamicRender'], ]; - return $pageOptions; + return $pageData; } public function navigation() diff --git a/content/themes/fipamo-default-v2/base.blade.php b/content/themes/fipamo-default-v2/base.blade.php index 50e845e..9eef8ca 100644 --- a/content/themes/fipamo-default-v2/base.blade.php +++ b/content/themes/fipamo-default-v2/base.blade.php @@ -2,7 +2,12 @@ @php if(isset($debug)) { - $assetPath = '/theme/'; + if($debug) + { + $assetPath = '/theme/'; + }else{ + $assetPath = '/assets/'; + } }else{ $assetPath = '/assets/'; }