diff --git a/public/index.php b/public/index.php index 2825b3b..0ed91d5 100644 --- a/public/index.php +++ b/public/index.php @@ -119,6 +119,21 @@ class CodePressCMS { } elseif (file_exists($filePath . '.html')) { $actualFilePath = $filePath . '.html'; $result = $this->parseHTML(file_get_contents($actualFilePath)); + } elseif (is_dir($filePath)) { + // Check for index files in directory + if (file_exists($filePath . '/index.md')) { + $actualFilePath = $filePath . '/index.md'; + $result = $this->parseMarkdown(file_get_contents($actualFilePath)); + } elseif (file_exists($filePath . '/index.php')) { + $actualFilePath = $filePath . '/index.php'; + $result = $this->parsePHP($actualFilePath); + } elseif (file_exists($filePath . '/index.html')) { + $actualFilePath = $filePath . '/index.html'; + $result = $this->parseHTML(file_get_contents($actualFilePath)); + } else { + // Generate directory listing + return $this->generateDirectoryListing($filePath, $page); + } } elseif (file_exists($filePath)) { $actualFilePath = $filePath; $extension = pathinfo($filePath, PATHINFO_EXTENSION); @@ -166,6 +181,41 @@ class CodePressCMS { return round($bytes, 2) . ' ' . $units[$pow]; } + private function generateDirectoryListing($dirPath, $urlPath) { + $title = ucfirst(basename($dirPath)); + $content = '
'; + + $items = scandir($dirPath); + sort($items); + + foreach ($items as $item) { + if ($item[0] === '.') continue; + + $path = $dirPath . '/' . $item; + $relativePath = $urlPath . '/' . $item; + $itemName = ucfirst(pathinfo($item, PATHINFO_FILENAME)); + + if (is_dir($path)) { + $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 .= ''; + } + } + + $content .= '
'; + + return [ + 'title' => $title, + 'content' => $content + ]; + } + private function getSearchResults() { $query = $_GET['search']; $content = '

Search Results for: "' . htmlspecialchars($query) . '"

'; @@ -324,11 +374,8 @@ class CodePressCMS { $dirPath = $this->config['content_dir'] . '/' . $path; $hasIndex = file_exists($dirPath . '/index.md') || file_exists($dirPath . '/index.php') || file_exists($dirPath . '/index.html'); - if ($hasIndex) { - $breadcrumb .= ''; - } else { - $breadcrumb .= ''; - } + // Always make breadcrumb items clickable, CMS will generate index if missing + $breadcrumb .= ''; } }