From ca86ab290955f65e350ed2e6fb7a90436a84e448 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Mon, 26 Aug 2024 10:47:29 +0100 Subject: [PATCH] site: Fix missing mimetype icons Signed-off-by: Ryan Northey --- site/pelicanconf.py | 44 ++++++++++++++++--------------- site/theme/templates/_macros.html | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/site/pelicanconf.py b/site/pelicanconf.py index 30ded5d..a2d515a 100644 --- a/site/pelicanconf.py +++ b/site/pelicanconf.py @@ -64,25 +64,25 @@ INDEX_SAVE_AS = 'index.html' MIME_TO_ICON = { - 'application/pdf': 'fa-file-pdf', - 'application/msword': 'fa-file-word', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'fa-file-word', - 'application/vnd.ms-excel': 'fa-file-excel', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'fa-file-excel', - 'image/jpeg': 'fa-file-image', - 'image/png': 'fa-file-image', - 'video/mp4': 'fa-file-video', - 'video/x-msvideo': 'fa-file-video', - 'audio/mpeg': 'fa-file-audio', - 'audio/wav': 'fa-file-audio', - 'application/zip': 'fa-file-archive', - 'application/x-tar': 'fa-file-archive', - 'text/plain': 'fa-file-alt', - 'application/octet-stream': 'fa-file', + 'application/pdf': 'fas fa-file-pdf', + 'application/msword': 'fas fa-file-word', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'fas fa-file-word', + 'application/vnd.ms-excel': 'fas fa-file-excel', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'fas fa-file-excel', + 'image/jpeg': 'fas fa-file-image', + 'image/png': 'fas fa-file-image', + 'video/mp4': 'fas fa-file-video', + 'video/x-msvideo': 'fas fa-file-video', + 'audio/mpeg': 'fas fa-file-audio', + 'audio/wav': 'fas fa-file-audio', + 'application/zip': 'fas fa-file-archive', + 'application/x-tar': 'fas fa-file-archive', + 'text/plain': 'fas fa-file-alt', + 'application/octet-stream': 'fas fa-file', "application/vnd.debian.binary-package": "debian-icon", "application/x-debian-package": "debian-icon", - "application/pgp-keys": "fa-key", - "application/pgp-signature": "fa-file-signature"} + "application/pgp-keys": "fa fa-key", + "application/pgp-signature": "fas fa-file-signature"} mimetypes.add_type('application/pgp-keys', '.key') mimetypes.add_type('application/pgp-signature', '.gpg') @@ -132,7 +132,7 @@ def _add_file_to_structure(self, directory_structure, path): current = directory_structure if len(components) == 1: - directory_structure["files"][path] = {} + directory_structure["files"][path] = {"class": self.class_for_file(components[0])} return for part in components[:-1]: @@ -141,10 +141,11 @@ def _add_file_to_structure(self, directory_structure, path): current["files"][components[-1]] = {"class": self.class_for_file(components[-1])} def class_for_file(self, filename): - mime_type, encoding = mimetypes.guess_type(filename) - if encoding in ["gzip", "bz2"]: + mimetype, encoding = mimetypes.guess_type(filename) + + if not mimetype and encoding in ["gzip", "bzip2"]: return "fa-compress" - return self.mime_to_icon.get(mime_type) or self.mime_to_icon.get("application/octet-stream") + return self.mime_to_icon.get(mimetype) or self.mime_to_icon.get("application/octet-stream") class Indexer(object): @@ -163,6 +164,7 @@ def walk(self, directory, path=""): files = ["signing.key"] + pathlib.Path("data/file_list.txt").read_text().splitlines() + DIRECTORY_STRUCTURE = FileTree(files).as_dict diff --git a/site/theme/templates/_macros.html b/site/theme/templates/_macros.html index 2359169..c5fc3b5 100644 --- a/site/theme/templates/_macros.html +++ b/site/theme/templates/_macros.html @@ -34,7 +34,7 @@

Browse the apt repository

{% for path, data in directory.files.items() %} - + {{ path }}