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
This commit is contained in:
ro 2024-03-28 16:42:37 -06:00
parent 9a716acb29
commit 1f62e6f816
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
5 changed files with 78 additions and 150 deletions

View file

@ -41,58 +41,16 @@ class ThemeController extends Controller
$template = $currentTheme . '.index' : $template = $currentTheme . '.index' :
$template = $currentTheme . '.page'; $template = $currentTheme . '.page';
$page = $this->pages->getById('532E2250-F8CB-4E87-9782-8AFBEE88DD5E'); $page = $this->pages->getById('532E2250-F8CB-4E87-9782-8AFBEE88DD5E');
$data = $this->sort->page($page); $pageData = $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'],
];
break; break;
case "tags": case "tags":
$template = $currentTheme . '.tags'; $template = $currentTheme . '.tags';
$data = $this->sort->tags(); $pageData = $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))]
],
];
break; break;
case "archives": case "archives":
case "archive": case "archive":
$template = $currentTheme . '.archive'; $template = $currentTheme . '.archive';
$data = $this->sort->archive(); $pageData = $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))]
],
];
break; break;
} }
if ($this->auth::status()) { if ($this->auth::status()) {

View file

@ -6,7 +6,6 @@ use App\Interfaces\PageRepositoryInterface;
use App\Services\SettingsService; use App\Services\SettingsService;
use App\Services\ContentService; use App\Services\ContentService;
use App\Services\PaginateService; use App\Services\PaginateService;
use App\Services\StringService;
use App\Services\DocService; use App\Services\DocService;
use App\Services\SortingService; use App\Services\SortingService;
use App\Services\RenderService; use App\Services\RenderService;
@ -18,7 +17,6 @@ class PageRepository implements PageRepositoryInterface
protected $setttings; protected $setttings;
protected $paginate; protected $paginate;
protected $pages; protected $pages;
protected $strings;
protected $docs; protected $docs;
protected $sort; protected $sort;
protected $render; protected $render;
@ -27,7 +25,6 @@ class PageRepository implements PageRepositoryInterface
ContentService $contentService, ContentService $contentService,
SettingsService $settingsService, SettingsService $settingsService,
PaginateService $paginateService, PaginateService $paginateService,
StringService $stringService,
DocService $docService, DocService $docService,
SortingService $sortingService, SortingService $sortingService,
RenderService $renderService RenderService $renderService
@ -35,7 +32,6 @@ class PageRepository implements PageRepositoryInterface
$this->content = $contentService; $this->content = $contentService;
$this->settings = $settingsService; $this->settings = $settingsService;
$this->paginate = $paginateService; $this->paginate = $paginateService;
$this->strings = $stringService;
$this->docs = $docService; $this->docs = $docService;
$this->sort = $sortingService; $this->sort = $sortingService;
$this->render = $renderService; $this->render = $renderService;
@ -103,7 +99,7 @@ class PageRepository implements PageRepositoryInterface
// grab current index from settings and update // grab current index from settings and update
$id = $task != 'create' ? $body->id : $this->settings->getSettings()['library_stats']['current_index']; $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 //set variables post body for saving
$body->id = $id; $body->id = $id;
$body->uuid = $uuid; $body->uuid = $uuid;

View file

@ -57,20 +57,8 @@ class RenderService
public function archive() public function archive()
{ {
$template = $this->theme . '.archive'; $template = $this->theme . '.archive';
$data = $this->sort->archive(); $pageData = $this->sort->archive(false);
$pageData = [ $location = '../public/archives.html';
'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( File::put(
$location, $location,
view($template) view($template)
@ -81,21 +69,18 @@ class RenderService
public function tags() public function tags()
{ {
$data = $this->sort->tags(); $data = $this->sort->tags(false);
foreach ($data['tags'] as $item) { foreach ($data['tags'] as $item) {
//$template = 'tags.twig'; //$template = 'tags.twig';
$template = $this->theme . '.tags'; $template = $this->theme . '.tags';
$pageData = [ $pageData = [
'theme' => $this->theme, // for theme kit 'theme' => $this->theme, // for theme kit
'title' => 'Pages Tagged as ' . $item['tag_name'], 'title' => 'Pages Tagged as ' . $item['tag_name'],
'dynamicRender' => $data['info']['dynamicRender'], 'dynamicRender' => $data['dynamicRender'],
'info' => $data['info'], 'info' => $data['info'],
'menu' => $data['info']['menu'], 'menu' => $data['menu'],
'pages' => $item['pages'], 'pages' => $item['pages'],
'media' => [ 'media' => $data['media'],
['file' => $data['info']['image'],
'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))]
],
]; ];
$location = '../public/tags/' . $item['slug'] . '.html'; $location = '../public/tags/' . $item['slug'] . '.html';
@ -122,22 +107,7 @@ class RenderService
$template = $this->theme . '.index' : $template = $this->theme . '.index' :
$template = $this->theme . '.page'; $template = $this->theme . '.page';
$data = $this->sort->page($page); $pageData = $this->sort->page($page, false);
$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')) { if (str_contains($page['layout'], 'index')) {
$location = '../public/index.html'; $location = '../public/index.html';

View file

@ -14,6 +14,7 @@ class SortingService
private $settings; private $settings;
private $contents; private $contents;
private $themes; private $themes;
private $info = [];
public function __construct( public function __construct(
SettingsService $settingsService, SettingsService $settingsService,
@ -23,9 +24,22 @@ class SortingService
$this->settings = $settingsService; $this->settings = $settingsService;
$this->contents = $contentService; $this->contents = $contentService;
$this->themes = $themeService; $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(); $pages = $this->contents->loadAllPages();
foreach ($pages as $page) { foreach ($pages as $page) {
@ -44,24 +58,23 @@ class SortingService
} }
} }
} }
$global = $this->settings->getGlobal();
$tagData = []; $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 = [ $tagData = [
'tags' => $this->p_tags, 'debug' => $debug, // for theme kit
'info' => $pageInfo, '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; return $tagData;
} }
@ -84,18 +97,15 @@ class SortingService
return $tagged; return $tagged;
} }
public function archive() public function archive($debug = true)
{ {
$pages = $this->contents->loadAllPages(); $pages = $this->contents->loadAllPages();
$years = []; $years = [];
$archive = []; $archive = [];
foreach ($pages as $page) { foreach ($pages as $page) {
// $year = date("Y", date($page["rawCreated"]));
$date = explode('/', $page['path']); $date = explode('/', $page['path']);
// echo $page["title"] . " : " . $year . "\n";
if (!find($years, ['year' => trim($date[0])])) { if (!find($years, ['year' => trim($date[0])])) {
$findPages = filter($pages, ['createdYear' => trim($date[0])]); $findPages = filter($pages, ['createdYear' => trim($date[0])]);
// var_dump($findPages);
array_push( array_push(
$years, $years,
[ [
@ -108,7 +118,6 @@ class SortingService
foreach ($years as $year) { foreach ($years as $year) {
$sorted = []; $sorted = [];
$filtered = filter($pages, ['createdYear' => $year['year']]); $filtered = filter($pages, ['createdYear' => $year['year']]);
foreach ($filtered as $obj) { foreach ($filtered as $obj) {
$month = date('m', date($obj['rawCreated'])); $month = date('m', date($obj['rawCreated']));
if (!find($sorted, ['month' => $month])) { if (!find($sorted, ['month' => $month])) {
@ -134,41 +143,29 @@ class SortingService
'year_data' => $sorted, 'year_data' => $sorted,
]); ]);
} }
$global = $this->settings->getGlobal();
$archive_data = []; $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 = [ $archiveData = [
'archive' => $this->p_archive, 'debug' => $debug, // for theme kit
'info' => $pageInfo, '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; return $archiveData;
} }
public function page($page) public function page($page, $debug = true)
{ {
$global = $this->settings->getGlobal();
$pageOptions = []; $pageOptions = [];
$tags = [];
$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 = [];
if (isset($page['tags'])) { if (isset($page['tags'])) {
$taglist = explode(',', $page['tags']); $taglist = explode(',', $page['tags']);
foreach ($taglist as $tag) { foreach ($taglist as $tag) {
@ -194,8 +191,8 @@ class SortingService
$ext = pathinfo($item, PATHINFO_EXTENSION); $ext = pathinfo($item, PATHINFO_EXTENSION);
if ($ext != 'mp4' && !$set) { if ($ext != 'mp4' && !$set) {
$pageInfo['image'] = $pageInfo['baseURL'] . $item; $this->info['image'] = $this->info['baseURL'] . $item;
$set = true; $set = true;
} }
} }
} }
@ -231,21 +228,23 @@ class SortingService
} }
} }
$pageOptions = [ $pageData = [
'title' => $page['title'], "debug" => $debug,
'background' => $page['feature'], "theme" => $this->info['theme'],
'content' => $page['html'], "status" => session('member') != null ? true : false,
'meta' => $meta, "title" => $page['title'],
'recent' => $recent, "meta" => $meta,
'featured' => $featured, "menu" => $this->settings->getMenu(),
'info' => $pageInfo, "info" => $this->info,
'menu' => $this->settings->getMenu(), "media" => $page['media'],
'dynamicRender' => $global['dynamicRender'], "files" => $page['docs'],
'media' => $page['media'], "content" => $page['html'],
'files' => $page['docs'], "recent" => $recent,
'tags' => $meta['tags'], "feature" => $featured,
"tags" => $meta['tags'],
"dynamicRender" => $this->info['dynamicRender'],
]; ];
return $pageOptions; return $pageData;
} }
public function navigation() public function navigation()

View file

@ -2,7 +2,12 @@
@php @php
if(isset($debug)) if(isset($debug))
{ {
$assetPath = '/theme/'; if($debug)
{
$assetPath = '/theme/';
}else{
$assetPath = '/assets/';
}
}else{ }else{
$assetPath = '/assets/'; $assetPath = '/assets/';
} }