Compare commits
No commits in common. "186e63ae47e7aca0474e018bbb07cf1cd7820c88" and "529ced6a2630605fc60cbd31041ca8780e5e85bf" have entirely different histories.
186e63ae47
...
529ced6a26
@ -22,9 +22,6 @@ services:
|
||||
App\EventSubscriber\ExceptionListener:
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: kernel.exception }
|
||||
App\Service\Page:
|
||||
arguments: [ '@kernel']
|
||||
|
||||
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
|
@ -2,25 +2,27 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\Page;
|
||||
use App\Repository\Page;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class DefaultController extends AbstractController
|
||||
{
|
||||
#[Route('/{slug}', name: 'default', requirements: ['slug' => '[a-zA-Z0-9\/]+'])]
|
||||
public function DefaultAction(Page $page, string $slug = 'index')
|
||||
public function DefaultAction(Request $request, Page $page, KernelInterface $kernel, string $slug = 'index')
|
||||
{
|
||||
$return = $page->getPage($slug);
|
||||
$return = $page->getPage($kernel, $slug);
|
||||
$response = new Response('', (int)$return['status']);
|
||||
return $this->render('/page.html.twig', $return, $response);
|
||||
}
|
||||
|
||||
#[Route('/error/{status}', name: 'error', requirements: ['status' => '[0-9]{3}'], priority: 2)]
|
||||
public function ErrorAction(Page $page, string $status = '404')
|
||||
public function ErrorAction(Request $request, Page $page, KernelInterface $kernel, string $status = '404')
|
||||
{
|
||||
$return = $page->getPage('error/' . $status);
|
||||
$return = $page->getPage($kernel, 'error/' . $status);
|
||||
$response = new Response('', (int)$status);
|
||||
return $this->render('/page.html.twig', $return, $response);
|
||||
}
|
||||
|
106
src/Repository/Page.php
Normal file
106
src/Repository/Page.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class Page
|
||||
{
|
||||
public function getPage(KernelInterface $kernel, string $page)
|
||||
{
|
||||
$parsedown = new \Parsedown();
|
||||
$return['js'] = [];
|
||||
$return['css'] = [];
|
||||
if(file_exists($kernel->getCacheDir() . '/pages/_header.md')) {
|
||||
$return['header'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/_header.md'));
|
||||
} elseif(file_exists($kernel->getCacheDir() . '/pages/_header.html')) {
|
||||
$return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_header.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/js/_header.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/js/_header.js'), true)),
|
||||
'file' => '/assets/js/_header.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/css/_header.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/css/_header.css'), true)),
|
||||
'file' => '/assets/css/_header.css'
|
||||
];
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getCacheDir() . '/pages/_nav.md')) {
|
||||
$return['nav'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/_nav.md'));
|
||||
} elseif(file_exists($kernel->getCacheDir() . '/pages/_nav.html')) {
|
||||
$return['nav'] = file_get_contents($kernel->getCacheDir() . '/pages/_nav.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/js/_nav.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/js/_nav.js'), true)),
|
||||
'file' => '/assets/js/_nav.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/css/_nav.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/css/_nav.css'), true)),
|
||||
'file' => '/assets/css/_nav.css'
|
||||
];
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getCacheDir() . '/pages/_footer.md')) {
|
||||
$return['footer'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/_footer.md'));
|
||||
} elseif(file_exists($kernel->getCacheDir() . '/pages/_footer.html')) {
|
||||
$return['footer'] = file_get_contents($kernel->getCacheDir() . '/pages/_footer.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/js/_footer.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/js/_footer.js'), true)),
|
||||
'file' => '/assets/js/_footer.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/css/_footer.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/css/_footer.css'), true)),
|
||||
'file' => '/assets/css/_footer.css'
|
||||
];
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.md')) {
|
||||
$return['content'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.md'));
|
||||
} elseif(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.html')) {
|
||||
$return['content'] = file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/js/' . $page . '.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/js/' . $page . '.js'), true)),
|
||||
'file' => '/assets/js/' . $page . '.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($kernel->getProjectDir() . '/public/assets/css/' . $page . '.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($kernel->getProjectDir() . '/public/assets/css/' . $page . '.css'), true)),
|
||||
'file' => '/assets/css/' . $page . '.css'
|
||||
];
|
||||
}
|
||||
|
||||
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true);
|
||||
$return['title'] = $titles[$page] ?? '';
|
||||
$return['status'] = '200';
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class Page
|
||||
{
|
||||
private KernelInterface $kernel;
|
||||
|
||||
/**
|
||||
* @param KernelInterface $kernel
|
||||
*/
|
||||
public function __construct(KernelInterface $kernel)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
}
|
||||
|
||||
public function getPage(string $page)
|
||||
{
|
||||
$parsedown = new \Parsedown();
|
||||
$return['js'] = [];
|
||||
$return['css'] = [];
|
||||
if(file_exists($this->kernel->getCacheDir() . '/pages/_header.md')) {
|
||||
$return['header'] = $parsedown->text(file_get_contents($this->kernel->getCacheDir() . '/pages/_header.md'));
|
||||
} elseif(file_exists($this->kernel->getCacheDir() . '/pages/_header.html')) {
|
||||
$return['header'] = file_get_contents($this->kernel->getCacheDir() . '/pages/_header.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/js/_header.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/js/_header.js'), true)),
|
||||
'file' => '/assets/js/_header.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/css/_header.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/css/_header.css'), true)),
|
||||
'file' => '/assets/css/_header.css'
|
||||
];
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getCacheDir() . '/pages/_nav.md')) {
|
||||
$return['nav'] = $parsedown->text(file_get_contents($this->kernel->getCacheDir() . '/pages/_nav.md'));
|
||||
} elseif(file_exists($this->kernel->getCacheDir() . '/pages/_nav.html')) {
|
||||
$return['nav'] = file_get_contents($this->kernel->getCacheDir() . '/pages/_nav.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/js/_nav.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/js/_nav.js'), true)),
|
||||
'file' => '/assets/js/_nav.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/css/_nav.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/css/_nav.css'), true)),
|
||||
'file' => '/assets/css/_nav.css'
|
||||
];
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getCacheDir() . '/pages/_footer.md')) {
|
||||
$return['footer'] = $parsedown->text(file_get_contents($this->kernel->getCacheDir() . '/pages/_footer.md'));
|
||||
} elseif(file_exists($this->kernel->getCacheDir() . '/pages/_footer.html')) {
|
||||
$return['footer'] = file_get_contents($this->kernel->getCacheDir() . '/pages/_footer.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/js/_footer.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/js/_footer.js'), true)),
|
||||
'file' => '/assets/js/_footer.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/css/_footer.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/css/_footer.css'), true)),
|
||||
'file' => '/assets/css/_footer.css'
|
||||
];
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getCacheDir() . '/pages/' . $page . '.md')) {
|
||||
$return['content'] = $parsedown->text(file_get_contents($this->kernel->getCacheDir() . '/pages/' . $page . '.md'));
|
||||
} elseif(file_exists($this->kernel->getCacheDir() . '/pages/' . $page . '.html')) {
|
||||
$return['content'] = file_get_contents($this->kernel->getCacheDir() . '/pages/' . $page . '.html');
|
||||
} else {
|
||||
throw new NotFoundHttpException('Some required files were not found');
|
||||
}
|
||||
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/js/' . $page . '.js')) {
|
||||
$return['js'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/js/' . $page . '.js'), true)),
|
||||
'file' => '/assets/js/' . $page . '.js'
|
||||
];
|
||||
}
|
||||
if(file_exists($this->kernel->getProjectDir() . '/public/assets/css/' . $page . '.css')) {
|
||||
$return['css'][] = [
|
||||
'sha384' => base64_encode(hash('sha384', file_get_contents($this->kernel->getProjectDir() . '/public/assets/css/' . $page . '.css'), true)),
|
||||
'file' => '/assets/css/' . $page . '.css'
|
||||
];
|
||||
}
|
||||
|
||||
$titles = json_decode(file_get_contents($this->kernel->getCacheDir() . '/pages/titles.json'), true);
|
||||
$return['title'] = $titles[$page] ?? '';
|
||||
$return['status'] = '200';
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>{% block title %}{% endblock %}{% if block("title") is not empty %} :: Jeroen De Meerleer{% endif %}</title>
|
||||
<title>Jeroen De Meerleer{% if block("title") is not empty %} :: {% block title %}{% endblock %}{% endif %}</title>
|
||||
|
||||
{% block styles %}{% endblock %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user