| | string $mediaType |
| | ): void { |
| | - $icon = $isDir ? '[dir]' : '[file]'; |
| | - |
| | - // Simple presentation logic for icons |
| | - if (!$isDir && str_starts_with($mediaType, 'image/')) { |
| | - $icon = '[img]'; |
| | - } |
| | + $iconClass = $this->getIconClass($isDir, $mediaType); |
| | |
| | $url = '?repo=' . urlencode($this->repoSafeName) . '&hash=' . $sha; |
| | |
| | echo '<a href="' . $url . '" class="file-item">'; |
| | echo '<span class="file-mode">' . $mode . '</span>'; |
| | echo '<span class="file-name">'; |
| | - echo '<span class="' . ($isDir ? 'dir' : 'file') . '-icon">' . $icon . '</span> '; |
| | + |
| | + // Render the FontAwesome Icon |
| | + echo '<i class="fas ' . $iconClass . '" style="width: 20px; text-align: center; margin-right: 5px; color: #7a828e;"></i>'; |
| | + |
| | echo htmlspecialchars($name); |
| | echo '</span>'; |
| | |
| | if ($time) { |
| | echo '<span class="file-date" style="color: #8b949e; font-size: 0.8em; margin-left: auto;">' . $time . '</span>'; |
| | } |
| | |
| | echo '</a>'; |
| | + } |
| | + |
| | + /** |
| | + * Maps media types to FontAwesome 6 icon classes. |
| | + */ |
| | + private function getIconClass(bool $isDir, string $mime): string { |
| | + if ($isDir) { |
| | + return 'fa-folder'; |
| | + } |
| | + |
| | + // Explicit Mime Matches |
| | + if ($mime === 'application/pdf') return 'fa-file-pdf'; |
| | + |
| | + // Archives |
| | + if (in_array($mime, [ |
| | + 'application/zip', 'application/x-tar', 'application/gzip', |
| | + 'application/x-bzip2', 'application/vnd.rar', 'application/x-7z-compressed' |
| | + ])) { |
| | + return 'fa-file-archive'; |
| | + } |
| | + |
| | + // Broad Categories (based on prefix) |
| | + if (str_starts_with($mime, 'image/')) return 'fa-file-image'; |
| | + if (str_starts_with($mime, 'audio/')) return 'fa-file-audio'; |
| | + if (str_starts_with($mime, 'video/')) return 'fa-file-video'; |
| | + |
| | + // Code / Text |
| | + if (str_starts_with($mime, 'text/')) return 'fa-file-code'; |
| | + |
| | + // Common Application Types behaving like code/text |
| | + if ( |
| | + str_contains($mime, 'javascript') || |
| | + str_contains($mime, 'json') || |
| | + str_contains($mime, 'xml') || |
| | + str_contains($mime, 'php') || |
| | + str_contains($mime, 'sh') |
| | + ) { |
| | + return 'fa-file-code'; |
| | + } |
| | + |
| | + // Default fallback |
| | + return 'fa-file'; |
| | } |
| | } |