KT-personal-website/app/Controllers/Page.php

48 lines
1.2 KiB
PHP
Raw Normal View History

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);
require __DIR__ . '/../../template/page.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
function title() {
return ucfirst($this->title);
}
}