Enable directory browsing and clickable breadcrumbs
- Made all breadcrumb items clickable - Added automatic directory listing generation for folders without index files - Folders now show a list of their contents instead of 404 - Improved navigation UX by allowing browsing through folder structure
This commit is contained in:
parent
f2e06f3a75
commit
8e781fcdc4
@ -119,6 +119,21 @@ class CodePressCMS {
|
|||||||
} elseif (file_exists($filePath . '.html')) {
|
} elseif (file_exists($filePath . '.html')) {
|
||||||
$actualFilePath = $filePath . '.html';
|
$actualFilePath = $filePath . '.html';
|
||||||
$result = $this->parseHTML(file_get_contents($actualFilePath));
|
$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)) {
|
} elseif (file_exists($filePath)) {
|
||||||
$actualFilePath = $filePath;
|
$actualFilePath = $filePath;
|
||||||
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
|
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
|
||||||
@ -166,6 +181,41 @@ class CodePressCMS {
|
|||||||
return round($bytes, 2) . ' ' . $units[$pow];
|
return round($bytes, 2) . ' ' . $units[$pow];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function generateDirectoryListing($dirPath, $urlPath) {
|
||||||
|
$title = ucfirst(basename($dirPath));
|
||||||
|
$content = '<div class="list-group">';
|
||||||
|
|
||||||
|
$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 .= '<a href="?page=' . $relativePath . '" class="list-group-item list-group-item-action">';
|
||||||
|
$content .= '<i class="bi bi-folder me-2"></i> ' . $itemName;
|
||||||
|
$content .= '</a>';
|
||||||
|
} elseif (preg_match('/\.(md|php|html)$/', $item)) {
|
||||||
|
// Remove extension from URL for cleaner links
|
||||||
|
$cleanPath = preg_replace('/\.[^.]+$/', '', $relativePath);
|
||||||
|
$content .= '<a href="?page=' . $cleanPath . '" class="list-group-item list-group-item-action">';
|
||||||
|
$content .= '<i class="bi bi-file-text me-2"></i> ' . $itemName;
|
||||||
|
$content .= '</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$content .= '</div>';
|
||||||
|
|
||||||
|
return [
|
||||||
|
'title' => $title,
|
||||||
|
'content' => $content
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
private function getSearchResults() {
|
private function getSearchResults() {
|
||||||
$query = $_GET['search'];
|
$query = $_GET['search'];
|
||||||
$content = '<h2>Search Results for: "' . htmlspecialchars($query) . '"</h2>';
|
$content = '<h2>Search Results for: "' . htmlspecialchars($query) . '"</h2>';
|
||||||
@ -324,11 +374,8 @@ class CodePressCMS {
|
|||||||
$dirPath = $this->config['content_dir'] . '/' . $path;
|
$dirPath = $this->config['content_dir'] . '/' . $path;
|
||||||
$hasIndex = file_exists($dirPath . '/index.md') || file_exists($dirPath . '/index.php') || file_exists($dirPath . '/index.html');
|
$hasIndex = file_exists($dirPath . '/index.md') || file_exists($dirPath . '/index.php') || file_exists($dirPath . '/index.html');
|
||||||
|
|
||||||
if ($hasIndex) {
|
// Always make breadcrumb items clickable, CMS will generate index if missing
|
||||||
$breadcrumb .= '<li class="breadcrumb-item"><a href="?page=' . $path . '/index">' . $title . '</a></li>';
|
$breadcrumb .= '<li class="breadcrumb-item"><a href="?page=' . $path . '">' . $title . '</a></li>';
|
||||||
} else {
|
|
||||||
$breadcrumb .= '<li class="breadcrumb-item active" aria-current="page">' . $title . '</li>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user