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); $return = $page->getPage($kernel, 'error/' . $status);
$response = new Response('', (int)$status); $response = new Response('', (int)$status);
return $this->render('/page.html.twig', [ return $this->render('/page.html.twig', [
'nav' => $return['nav'],
'header' => $return['header'], 'header' => $return['header'],
'content' => $return['content'], 'content' => $return['content'],
'title' => $return['title'], 'title' => $return['title'],

View File

@ -10,16 +10,35 @@ class Page
{ {
public function getPage(KernelInterface $kernel, string $page) public function getPage(KernelInterface $kernel, string $page)
{ {
$return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_main.md'); $parsedown = new \Parsedown();
$return['nav'] = file_get_contents($kernel->getCacheDir() . '/pages/_nav.md'); if(file_exists($kernel->getCacheDir() . '/pages/_header.md')) {
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true); $return['header'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/_header.md'));
if(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.md')) { } elseif(file_exists($kernel->getCacheDir() . '/pages/_header.html')) {
$return['title'] = $titles[$page] ?? ''; $return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_header.html');
$return['content'] = file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.md');
$return['status'] = '200';
} else { } 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; 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 %} {% block content %}
<nav> <nav>
<div class="container py-3"> <div class="container py-3">
{{ nav | markdown | raw }} {{ nav | raw }}
</div> </div>
</nav> </nav>
<header> <header>
<div class="container py-4"> <div class="container py-4">
{{ header | markdown | raw }} {{ header | raw }}
</div> </div>
</header> </header>
<main> <main>
<div class="container py-4"> <div class="container py-4">
{{ content | markdown | raw }} {{ content | raw }}
</div> </div>
</main> </main>
{% endblock %} {% endblock %}