2024-10-22 12:26:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Utils\RenderHtml;
|
|
|
|
|
|
|
|
class Page {
|
|
|
|
|
|
|
|
private $title = 'Page';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders page content
|
|
|
|
*
|
|
|
|
* @param array $params An array of parameters for the page rendering
|
|
|
|
* @return string The rendered content for the page page
|
|
|
|
*/
|
|
|
|
function index(array $params): string {
|
|
|
|
ob_start();
|
|
|
|
$lastMod = 0;
|
|
|
|
|
|
|
|
$this->title = $page = str_replace('/', '', $params['requestUrl']);
|
|
|
|
$author = $params['config']['author'];
|
|
|
|
|
|
|
|
if (file_exists('../datas/pages/' . $page . '.md')) {
|
|
|
|
$pageContent = file_get_contents('../datas/pages/' . $page . '.md');
|
|
|
|
|
|
|
|
$modifiedDate = \DateTime::createFromFormat("U", filemtime('../datas/pages/' . $page . '.md'));
|
|
|
|
$lastMod = $modifiedDate->format(\DateTime::ATOM);
|
|
|
|
} else {
|
|
|
|
$pageContent = file_get_contents('../datas/pages/404.md');
|
|
|
|
}
|
|
|
|
|
|
|
|
$pageContent = RenderHtml::markdownToHtml($pageContent);
|
|
|
|
|
2024-12-06 11:34:32 +01:00
|
|
|
require __DIR__ . '/../../template/'.$params['config']['theme'].'/page.php';
|
2024-10-22 12:26:08 +02:00
|
|
|
|
|
|
|
$content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
function title() {
|
|
|
|
return ucfirst($this->title);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|