ENHANCEMENT: allowing HTML pages

This commit is contained in:
Jeroen De Meerleer 2023-03-22 11:49:46 +01:00
parent 434159b285
commit 1fff561ee1
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 31 additions and 31 deletions

View File

@ -28,6 +28,7 @@ class DefaultController extends AbstractController
$return = $page->getPage($kernel, 'error/' . $status);
$response = new Response('', (int)$status);
return $this->render('/page.html.twig', [
'nav' => $return['nav'],
'header' => $return['header'],
'content' => $return['content'],
'title' => $return['title'],

View File

@ -10,16 +10,35 @@ class Page
{
public function getPage(KernelInterface $kernel, string $page)
{
$return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_main.md');
$return['nav'] = file_get_contents($kernel->getCacheDir() . '/pages/_nav.md');
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true);
if(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.md')) {
$return['title'] = $titles[$page] ?? '';
$return['content'] = file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.md');
$return['status'] = '200';
$parsedown = new \Parsedown();
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();
throw new NotFoundHttpException('Some required files were not found');
}
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->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');
}
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true);
$return['title'] = $titles[$page] ?? '';
$return['status'] = '200';
return $return;
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('markdown', [$this, 'parseMarkdown']),
];
}
public function parseMarkdown(string $markdown) {
$parsedown = new \Parsedown();
return $parsedown->text($markdown);
}
}

View File

@ -3,17 +3,17 @@
{% block content %}
<nav>
<div class="container py-3">
{{ nav | markdown | raw }}
{{ nav | raw }}
</div>
</nav>
<header>
<div class="container py-4">
{{ header | markdown | raw }}
{{ header | raw }}
</div>
</header>
<main>
<div class="container py-4">
{{ content | markdown | raw }}
{{ content | raw }}
</div>
</main>
{% endblock %}