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.
This commit is contained in:
ro 2024-03-18 16:14:17 -06:00
parent efb2e4f0bd
commit a6b63ca551
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
6 changed files with 118 additions and 36 deletions

View file

@ -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' => [

View file

@ -64,7 +64,8 @@ class FipamoServiceProvider extends ServiceProvider
new ContentService(),
new StringService(),
),
new SettingsService(new DocService())
new SettingsService(new DocService()),
new ContentService(),
);
});

View file

@ -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();
}

View file

@ -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());
}
}
}

View file

@ -42,7 +42,7 @@
@endif
@endforeach
@else
@if($media != '')
@if(isset($media[0]) && $media != '')
@if($media[0]['type'] == "mp4")
<div id="0" role="slide">
<video controls autoplay muted>
@ -53,6 +53,8 @@
@else
<div id="0" role="slide" style="background: url({{ $media[0]['file'] }}) no-repeat center center / cover"></div>
@endif
@else
<div id="0" role="slide" style="background: url({{ $info['image'] }}) no-repeat center center / cover"></div>
@endif
@endif
</div>

View file

@ -5,15 +5,15 @@
@section('main-content')
<article>
<h1>{{ $title }}</h1>
@foreach($tags as $tag)
@foreach($pages as $page)
@if(isset($dynamicRender))
@if($dynamicRender == 'true')
<a href="{{ "/".$tag['path']."/".$tag['slug'] }}">{{ $tag['title'] }}</a><br/>
<a href="{{ "/".$page['path']."/".$page['slug'] }}">{{ $page['title'] }}</a><br/>
@else
<a href="{{ "/".$tag['path']."/".$tag['slug'].".html" }}">{{ $tag['title'] }}</a><br/>
<a href="{{ "/".$page['path']."/".$page['slug'].".html" }}">{{ $page['title'] }}</a><br/>
@endif
@else
<a href="{{ "/".$tag['path']."/".$tag['slug'].".html" }}">{{ $tag['title'] }}</a><br/>
<a href="{{ "/".$page['path']."/".$page['slug'].".html" }}">{{ $page['title'] }}</a><br/>
@endif
@endforeach
</article>