fipamo/app/Services/Assets/RenderService.php
ro ed6f028598
added layout varible to sorting, updated ignore
data sorting needed a new variable to differentiate between index page
rendering and standard page rendering, so that was added to the return
as well as updating the render script to include the variable that
wasn't being added for tags

also updated the git ignore file to ignore global images that are not
used by the base system. the script theme folder needs to be ignore as
well as that is going to updated by the theme itself for front end
coding and not used by the system
2024-06-26 14:08:53 -06:00

133 lines
4 KiB
PHP

<?php
namespace App\Services\Assets;
use Illuminate\Support\Facades\File;
use App\Services\Data\SortingService;
use App\Services\Data\SettingsService;
use App\Services\Data\ContentService;
class RenderService
{
private $sort;
private $settings;
private $contents;
private $pageInfo;
private $menu;
private $background;
private $theme;
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 publishAll()
{
$message = [];
$dynamicRender = $this->settings->getGlobal()['dynamicRender'];
if (isset($dynamicRender) && $dynamicRender === 'true') {
$message = [
'message' => 'Auto Rendering is already enabled!',
'type' => 'RENDER_SUCCESS',
];
} else {
try {
$this->archive();
$this->tags();
$this->pages();
$message = [
'message' => 'Site Rendered. GOOD EFFORT',
'type' => 'RENDER_SUCCESS',
];
} catch (Error $error) {
$message = [
'message' => 'Issue With Rendering. DONT PANIC',
'type' => 'RENDER_ERROR',
];
}
}
return $message;
}
public function archive()
{
$template = $this->theme . '.archive';
$pageData = $this->sort->archive(false);
$location = '../public/archives.html';
File::put(
$location,
view($template)
->with($pageData)
->render()
);
}
public function 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['dynamicRender'],
'layout' => 'page',
'info' => $data['info'],
'menu' => $data['menu'],
'pages' => $item['pages'],
'media' => $data['media'],
];
$location = '../public/tags/' . $item['slug'] . '.html';
if (!is_dir('../public/tags')) {
mkdir('../public/tags', 0755, true);
}
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';
$pageData = $this->sort->page($page, false);
if (str_contains($page['layout'], 'index')) {
$location = '../public/index.html';
} else {
// 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());
}
}
}