Compare commits
2 Commits
529ced6a26
...
186e63ae47
Author | SHA1 | Date | |
---|---|---|---|
186e63ae47 | |||
563c97925f |
@ -22,6 +22,9 @@ services:
|
|||||||
App\EventSubscriber\ExceptionListener:
|
App\EventSubscriber\ExceptionListener:
|
||||||
tags:
|
tags:
|
||||||
- { name: kernel.event_listener, event: kernel.exception }
|
- { name: kernel.event_listener, event: kernel.exception }
|
||||||
|
App\Service\Page:
|
||||||
|
arguments: [ '@kernel']
|
||||||
|
|
||||||
|
|
||||||
# add more service definitions when explicit configuration is needed
|
# add more service definitions when explicit configuration is needed
|
||||||
# please note that last definitions always *replace* previous ones
|
# please note that last definitions always *replace* previous ones
|
||||||
|
@ -2,27 +2,25 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Repository\Page;
|
use App\Service\Page;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
class DefaultController extends AbstractController
|
class DefaultController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/{slug}', name: 'default', requirements: ['slug' => '[a-zA-Z0-9\/]+'])]
|
#[Route('/{slug}', name: 'default', requirements: ['slug' => '[a-zA-Z0-9\/]+'])]
|
||||||
public function DefaultAction(Request $request, Page $page, KernelInterface $kernel, string $slug = 'index')
|
public function DefaultAction(Page $page, string $slug = 'index')
|
||||||
{
|
{
|
||||||
$return = $page->getPage($kernel, $slug);
|
$return = $page->getPage($slug);
|
||||||
$response = new Response('', (int)$return['status']);
|
$response = new Response('', (int)$return['status']);
|
||||||
return $this->render('/page.html.twig', $return, $response);
|
return $this->render('/page.html.twig', $return, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/error/{status}', name: 'error', requirements: ['status' => '[0-9]{3}'], priority: 2)]
|
#[Route('/error/{status}', name: 'error', requirements: ['status' => '[0-9]{3}'], priority: 2)]
|
||||||
public function ErrorAction(Request $request, Page $page, KernelInterface $kernel, string $status = '404')
|
public function ErrorAction(Page $page, string $status = '404')
|
||||||
{
|
{
|
||||||
$return = $page->getPage($kernel, 'error/' . $status);
|
$return = $page->getPage('error/' . $status);
|
||||||
$response = new Response('', (int)$status);
|
$response = new Response('', (int)$status);
|
||||||
return $this->render('/page.html.twig', $return, $response);
|
return $this->render('/page.html.twig', $return, $response);
|
||||||
}
|
}
|
||||||
|
@ -1,106 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
116
src/Service/Page.php
Normal file
116
src/Service/Page.php
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<?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>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
<title>Jeroen De Meerleer{% if block("title") is not empty %} :: {% block title %}{% endblock %}{% endif %}</title>
|
<title>{% block title %}{% endblock %}{% if block("title") is not empty %} :: Jeroen De Meerleer{% endif %}</title>
|
||||||
|
|
||||||
{% block styles %}{% endblock %}
|
{% block styles %}{% endblock %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user