cleaned up the code to get a massive boost to publishing and page rendering speeds the issue was related to pages being collected and transformed into objects the system could use multiple times, resulting in sluggish rendering due to available memory getting drained to accomodate a long script running more than it was needed. edited the rendering process so the script is only called one and the data is passed to the respective functions that require that data. also plugged in some minor manual garbage collection that speed up the process a bit more there was also a bug with rendering the tags file that was resulting in the `tags.json` file being unusually large. the issue was tags were getting replicated in the process resulting in adding duplicates to the tag file everytime it was run. go rid of the unnecessary function that was calling the replicate tags array and now the tags file is it's appropriate size whew, this turned out to be a big one that wasn't meant to be, but the peformance boost was worth it
169 lines
5.9 KiB
PHP
169 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Services\Assets\AssetService;
|
|
use App\Services\Data\SettingsService;
|
|
use App\Services\Data\SortingService;
|
|
use App\Services\Upkeep\InitService;
|
|
use App\Http\Controllers\DashController;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
use function _\find;
|
|
|
|
class FrontController extends Controller
|
|
{
|
|
protected $settings;
|
|
protected PageRepositoryInterface $pages;
|
|
protected AssetService $assets;
|
|
protected SortingService $sort;
|
|
protected $init;
|
|
protected $dash;
|
|
protected $words;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepository,
|
|
SettingsService $settingsService,
|
|
AssetService $assetService,
|
|
SortingService $sortService,
|
|
InitService $initService,
|
|
DashController $dashController,
|
|
) {
|
|
$this->pages = $pageRepository;
|
|
$this->settings = $settingsService;
|
|
$this->assets = $assetService;
|
|
$this->sort = $sortService;
|
|
$this->init = $initService;
|
|
$this->dash = $dashController;
|
|
$this->words = ['words'];
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$template;
|
|
$pageData = [];
|
|
if ($this->configCheck()) {
|
|
$pages = $this->pages->getAll();
|
|
$global = $this->settings->getGlobal();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
if ($global['dynamicRender'] == 'true') {
|
|
$page = $pages->where('id', 0)->first();
|
|
$pageData = $this->sort->page($page, $pages, false);
|
|
$template = $currentTheme . '.index';
|
|
return view($template, $pageData);
|
|
} else {
|
|
if (is_file('../public/index.html')) {
|
|
return response()->file('../public/index.html');
|
|
} else {
|
|
return redirect()->intended('dashboard/start');
|
|
}
|
|
}
|
|
} else {
|
|
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
}
|
|
}
|
|
|
|
public function page($year, $month, $slug)
|
|
{
|
|
$template;
|
|
$pageData = [];
|
|
if ($this->configCheck()) {
|
|
$pages = $this->pages->getAll();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
$page = $this->pages->getBySlug($slug);
|
|
$pageData = $this->sort->page($page, $pages, false);
|
|
$template = $currentTheme . '.' . $page['layout'];
|
|
return view($template, $pageData);
|
|
}
|
|
}
|
|
|
|
public function menu($slug, $option = null)
|
|
{
|
|
$template;
|
|
$pageData = [];
|
|
if ($this->configCheck()) {
|
|
$pages = $this->pages->getAll();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
switch ($slug) {
|
|
case 'archive':
|
|
case 'archives':
|
|
$template = $currentTheme . '.archive';
|
|
$pageData = $this->sort->archive($pages, false);
|
|
break;
|
|
case 'tags':
|
|
$template = $currentTheme . '.tags';
|
|
$tags = $this->sort->tags($pages, false);
|
|
$tagData = find($tags['tags'], ['tag_name' => $option]);
|
|
$pageData = [
|
|
'theme' => $currentTheme, // for theme kit
|
|
'layout' => $tags['layout'],
|
|
'title' => 'Pages Tagged as ' . $option,
|
|
'dynamicRender' => $tags['dynamicRender'],
|
|
'info' => $tags['info'],
|
|
'menu' => $tags['menu'],
|
|
'pages' => $tagData['pages'],
|
|
'media' => $tags['media'],
|
|
];
|
|
break;
|
|
default:
|
|
$pages = $this->pages->getAll();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
$page = $this->pages->getBySlug($slug);
|
|
$pageData = $this->sort->page($page, $pages, false);
|
|
$template = $currentTheme . '.' . $page['layout'];
|
|
break;
|
|
}
|
|
|
|
return view($template, $pageData);
|
|
}
|
|
}
|
|
|
|
private function configCheck()
|
|
{
|
|
if (file_exists(env('FOLKS_PATH')) && file_exists(env('SETTINGS_PATH'))) {
|
|
return true;
|
|
} else {
|
|
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
}
|
|
}
|
|
|
|
public function things()
|
|
{
|
|
return $items = ['archive', 'archives', 'tags'];
|
|
}
|
|
|
|
public static function items()
|
|
{
|
|
if (file_exists(env('SETTINGS_PATH'))) {
|
|
//set permanent links
|
|
$items = ['archive', 'archives', 'tags'];
|
|
//grab menu items and set to array so router knows to look for them
|
|
$settings = json_decode(file_get_contents(env('SETTINGS_PATH')), true);
|
|
foreach ($settings['menu'] as $item) {
|
|
array_push($items, $item['slug']);
|
|
}
|
|
return $items;
|
|
} else {
|
|
//return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
// return redirect()->route('start');
|
|
return [];
|
|
}
|
|
}
|
|
|
|
//setup up a new site or restore from back up
|
|
public function init($task, Request $request)
|
|
{
|
|
$result = [];
|
|
switch ($task) {
|
|
case 'fresh':
|
|
$result = $this->init->fresh(json_decode($request->getContent()));
|
|
break;
|
|
case 'restore':
|
|
$result = $this->init->restore($request);
|
|
break;
|
|
}
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
}
|
|
}
|