From a517a9942db6fa90d30e7b3bd7e3385e06c41330 Mon Sep 17 00:00:00 2001 From: Chris Pointon Date: Tue, 25 Apr 2023 16:29:30 +0100 Subject: [PATCH] Make font loading walk subdirectories --- src/plugins/social/plugin.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/social/plugin.py b/src/plugins/social/plugin.py index 06b43714e..d9f017308 100644 --- a/src/plugins/social/plugin.py +++ b/src/plugins/social/plugin.py @@ -393,14 +393,22 @@ class SocialPlugin(BasePlugin[SocialPluginConfig]): name = "Roboto" # Retrieve font files, if not already done - files = os.listdir(self.cache) - files = [file for file in files if file.endswith(".ttf") or file.endswith(".otf")] or ( + all_files=[] + # Check for cached files - note these may be in subfolders + for currentpath, folders, files in os.walk(self.cache): + for file in files: + all_files.append(os.path.join(currentpath, file)) + + # If none found, fetch from Google and try again + if len(all_files) == 0: self._load_font_from_google(name) - ) + for currentpath, folders, files in os.walk(self.cache): + for file in files: + all_files.append(os.path.join(currentpath, file)) # Map available font weights to file paths font = dict() - for file in files: + for file in all_files: match = re.search(r"-(\w+)\.[ot]tf$", file) if match: font[match.group(1)] = os.path.join(self.cache, file)