From 277f86346d16afce1d5f3f4ec289016cff8d080c Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Wed, 19 Nov 2025 16:05:24 +0100 Subject: [PATCH] Enhance directory listing with article previews - Replaced simple list with card-based layout - Added article previews (title + excerpt) - Removed rounded corners (rounded-0) - Added 'Lees meer' button - Improved visual hierarchy for folders vs files --- public/index.php | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/public/index.php b/public/index.php index 0ed91d5..2d981f6 100644 --- a/public/index.php +++ b/public/index.php @@ -183,7 +183,7 @@ class CodePressCMS { private function generateDirectoryListing($dirPath, $urlPath) { $title = ucfirst(basename($dirPath)); - $content = '
'; + $content = '
'; $items = scandir($dirPath); sort($items); @@ -196,15 +196,36 @@ class CodePressCMS { $itemName = ucfirst(pathinfo($item, PATHINFO_FILENAME)); if (is_dir($path)) { - $content .= ''; - $content .= ' ' . $itemName; - $content .= ''; + $content .= '
'; + $content .= '
'; + $content .= '
'; + $content .= '

' . $itemName . '

'; + $content .= '
'; } elseif (preg_match('/\.(md|php|html)$/', $item)) { // Remove extension from URL for cleaner links $cleanPath = preg_replace('/\.[^.]+$/', '', $relativePath); - $content .= ''; - $content .= ' ' . $itemName; - $content .= ''; + + // Get preview content + $preview = ''; + $fileContent = file_get_contents($path); + + // Extract title if possible + $fileTitle = $itemName; + if (preg_match('/^#\s+(.+)$/m', $fileContent, $matches)) { + $fileTitle = trim($matches[1]); + } + + // Extract preview text (first paragraph) + $fileContent = strip_tags($this->parseMarkdown($fileContent)['content']); + $preview = substr($fileContent, 0, 150) . '...'; + + $content .= '
'; + $content .= '
'; + $content .= '
'; + $content .= '

' . $fileTitle . '

'; + $content .= '

' . $preview . '

'; + $content .= 'Lees meer'; + $content .= '
'; } }