diff --git a/app/router.php b/app/router.php index b79ce48..a4adca3 100644 --- a/app/router.php +++ b/app/router.php @@ -129,7 +129,15 @@ function parseRequestPath(string $requestPath, string $contentDir, array $patter } if (is_dir($contentPath)) { - if ($file = findMatchingFile($contentPath, $patterns['single']) ?: findMatchingFile($contentPath, $patterns['page'])) { + // Check if directory has subdirectories + $hasSubdirs = !empty(array_filter( + scandir($contentPath) ?: [], + fn($item) => !in_array($item, ['.', '..']) && is_dir("$contentPath/$item") + )); + + // If directory has subdirectories, treat as directory (for list views) + // Otherwise, if it has a content file, treat as file + if (!$hasSubdirs && ($file = findMatchingFile($contentPath, $patterns['single']) ?: findMatchingFile($contentPath, $patterns['page']))) { return ['type' => 'file', 'path' => $file, 'needsSlash' => !$hasTrailingSlash]; } return ['type' => 'directory', 'path' => realpath($contentPath)]; @@ -376,6 +384,31 @@ switch ($parsedPath['type']) { renderFile("$dir/index.php"); } + // Check for page content file in this directory + $pageContent = null; + if ($pageFile = findMatchingFile($dir, $pageFilePatterns['page'])) { + $ext = pathinfo($pageFile, PATHINFO_EXTENSION); + ob_start(); + if ($ext === 'md') { + if (!class_exists('Parsedown')) { + require_once __DIR__ . '/vendor/Parsedown.php'; + } + echo (new Parsedown())->text(file_get_contents($pageFile)); + } else { + include $pageFile; + } + $pageContent = ob_get_clean(); + } + + // Load metadata for this directory + $metadata = loadMetadata($dir, $currentLang, $defaultLang); + + // Check for custom list template (prefer list-grid.php over list.php) + $customListGridTemplate = dirname(__DIR__) . '/custom/templates/list-grid.php'; + if (file_exists($customListGridTemplate)) { + $listTemplate = $customListGridTemplate; + } + // Default directory listing $subdirs = array_filter( scandir($dir) ?: [],