Add page-specific CSS support

Add helper function to find page-specific CSS files Add CSS loading to
base template Update rendering functions to include page CSS Update
router to include page CSS for static pages
This commit is contained in:
Ruben 2025-11-03 23:04:16 +01:00
parent 0b84615bf9
commit 6879fad5fb
7 changed files with 110 additions and 0 deletions

View file

@ -65,6 +65,23 @@ function findPdfFile(string $dirPath): ?string {
return $pdfs ? basename($pdfs[0]) : null;
}
function findPageCss(string $dirPath, string $contentDir): ?array {
$cssFile = "$dirPath/styles.css";
if (!file_exists($cssFile) || !is_file($cssFile)) {
return null;
}
// Generate URL path relative to content directory
$relativePath = str_replace($contentDir, '', $dirPath);
$relativePath = trim($relativePath, '/');
$cssUrl = '/' . ($relativePath ? $relativePath . '/' : '') . 'styles.css';
return [
'url' => $cssUrl,
'hash' => hash_file('md5', $cssFile)
];
}
function extractMetaDescription(string $dirPath, ?array $metadata, string $lang, string $defaultLang): ?string {
// 1. Check for search_description in metadata
if ($metadata && isset($metadata['search_description'])) {