2024-03-14 19:39:43 +01:00
|
|
|
<?php
|
|
|
|
|
2024-05-13 06:14:53 +02:00
|
|
|
namespace App\Services\Assets;
|
2024-03-14 19:39:43 +01:00
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
use Illuminate\Support\Facades\File;
|
2024-05-13 06:14:53 +02:00
|
|
|
use App\Services\Data\SortingService;
|
|
|
|
use App\Services\Data\SettingsService;
|
|
|
|
use App\Services\Data\ContentService;
|
2024-03-18 23:14:17 +01:00
|
|
|
|
2024-03-14 19:39:43 +01:00
|
|
|
class RenderService
|
|
|
|
{
|
2024-03-14 23:58:11 +01:00
|
|
|
private $sort;
|
|
|
|
private $settings;
|
2024-03-18 23:14:17 +01:00
|
|
|
private $contents;
|
2024-03-14 23:58:11 +01:00
|
|
|
private $pageInfo;
|
|
|
|
private $menu;
|
|
|
|
private $background;
|
2024-03-18 23:14:17 +01:00
|
|
|
private $theme;
|
2024-03-14 23:58:11 +01:00
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
public function __construct(
|
|
|
|
SortingService $sortingService,
|
|
|
|
SettingsService $settingsService,
|
|
|
|
ContentService $contentService
|
|
|
|
) {
|
2024-03-14 23:58:11 +01:00
|
|
|
$this->sort = $sortingService;
|
|
|
|
$this->settings = $settingsService;
|
2024-03-18 23:14:17 +01:00
|
|
|
$this->contents = $contentService;
|
|
|
|
$this->theme = $this->settings->getGlobal()['theme'];
|
2024-03-14 23:58:11 +01:00
|
|
|
}
|
|
|
|
|
2024-03-19 22:34:01 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
public function archive()
|
2024-03-14 19:39:43 +01:00
|
|
|
{
|
2024-03-18 23:14:17 +01:00
|
|
|
$template = $this->theme . '.archive';
|
2024-03-28 23:42:37 +01:00
|
|
|
$pageData = $this->sort->archive(false);
|
|
|
|
$location = '../public/archives.html';
|
2024-03-18 23:14:17 +01:00
|
|
|
File::put(
|
|
|
|
$location,
|
|
|
|
view($template)
|
|
|
|
->with($pageData)
|
|
|
|
->render()
|
|
|
|
);
|
|
|
|
}
|
2024-03-14 23:58:11 +01:00
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
public function tags()
|
|
|
|
{
|
2024-03-28 23:42:37 +01:00
|
|
|
$data = $this->sort->tags(false);
|
2024-03-18 23:14:17 +01:00
|
|
|
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'],
|
2024-03-28 23:42:37 +01:00
|
|
|
'dynamicRender' => $data['dynamicRender'],
|
2024-03-18 23:14:17 +01:00
|
|
|
'info' => $data['info'],
|
2024-03-28 23:42:37 +01:00
|
|
|
'menu' => $data['menu'],
|
2024-03-18 23:14:17 +01:00
|
|
|
'pages' => $item['pages'],
|
2024-03-28 23:42:37 +01:00
|
|
|
'media' => $data['media'],
|
2024-03-18 23:14:17 +01:00
|
|
|
];
|
2024-03-14 23:58:11 +01:00
|
|
|
|
|
|
|
$location = '../public/tags/' . $item['slug'] . '.html';
|
|
|
|
|
|
|
|
if (!is_dir('../public/tags')) {
|
|
|
|
mkdir('../public/tags', 0755, true);
|
|
|
|
}
|
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
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';
|
|
|
|
|
2024-03-28 23:42:37 +01:00
|
|
|
$pageData = $this->sort->page($page, false);
|
2024-03-18 23:14:17 +01:00
|
|
|
|
|
|
|
if (str_contains($page['layout'], 'index')) {
|
|
|
|
$location = '../public/index.html';
|
2024-03-14 23:58:11 +01:00
|
|
|
} else {
|
2024-03-18 23:14:17 +01:00
|
|
|
// 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';
|
|
|
|
}
|
2024-03-14 23:58:11 +01:00
|
|
|
}
|
2024-03-18 23:14:17 +01:00
|
|
|
File::put($location, view($template)->with($pageData)->render());
|
2024-03-14 23:58:11 +01:00
|
|
|
}
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
}
|