From 4277f4d96bf8832bc0c5e07dea1bee8c489fae9e Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Tue, 8 Sep 2020 19:48:49 -0400
Subject: [PATCH] WIP Photos: case insensitive file extensions, fix config.

---
 my_plugins/photos/{photos.py => __init__.py} | 20 +++++++++++---------
 pelicanconf.py                               |  2 +-
 2 files changed, 12 insertions(+), 10 deletions(-)
 rename my_plugins/photos/{photos.py => __init__.py} (97%)

diff --git a/my_plugins/photos/photos.py b/my_plugins/photos/__init__.py
similarity index 97%
rename from my_plugins/photos/photos.py
rename to my_plugins/photos/__init__.py
index 5692d3c..2dcf4ae 100644
--- a/my_plugins/photos/photos.py
+++ b/my_plugins/photos/__init__.py
@@ -402,6 +402,11 @@ def galleries_string_decompose(gallery_string):
 
 def process_gallery(generator, content, location):
 
+    RE_PHOTO = re.compile('.*\.jpg', re.I)
+    RE_VIDEO = re.compile('.*\.mp4', re.I)
+    RE_HIDDEN_FILE = re.compile('^\..*')
+    RE_TEXT_FILE = re.compile('.*\.txt', re.I)
+
     content.photo_gallery = []
 
     galleries = galleries_string_decompose(location)
@@ -439,18 +444,15 @@ def process_gallery(generator, content, location):
 
             title = gallery['title']
             for item in sorted(os.listdir(dir_gallery)):
-                if item.startswith('.'):
-                    continue
-                if item.endswith('.txt'):
+                if any(regex.match(item) for regex in (RE_HIDDEN_FILE, RE_TEXT_FILE)):
                     continue
                 if item in blacklist:
                     continue
-                if item.endswith('.mp4.jpg'):
-                    if os.path.isfile(
-                         os.path.join(dir_gallery, os.path.splitext(item)[0])):
-                        continue
+                if RE_VIDEO.match(item) and os.path.isfile(
+                     os.path.join(dir_gallery, os.path.splitext(item)[0])):
+                    continue
                 thumb = os.path.splitext(item)[0] + 't.jpg'
-                if item.endswith('.jpg'):
+                if RE_PHOTO.match(item):
                     enqueue_resize(
                         os.path.join(dir_gallery, item),
                         os.path.join(dir_photo, item),
@@ -459,7 +461,7 @@ def process_gallery(generator, content, location):
                         os.path.join(dir_gallery, item),
                         os.path.join(dir_thumb, thumb),
                         generator.settings['PHOTO_THUMB'])
-                elif item.endswith('.mp4'):
+                elif RE_VIDEO.match(item):
                     enqueue_copy(
                         os.path.join(dir_gallery, item),
                         os.path.join(generator.output_path, dir_photo, item),
diff --git a/pelicanconf.py b/pelicanconf.py
index bee56d0..a2a2cfd 100644
--- a/pelicanconf.py
+++ b/pelicanconf.py
@@ -9,7 +9,7 @@ SITENAME = 'Anton Sarukhanov'
 SITESUBTITLE = 'Full-Stack Developer'
 SITEURL = os.environ.get('SITEURL')
 
-PLUGIN_PATHS = ['plugins']
+PLUGIN_PATHS = ['my_plugins']
 PLUGINS = ['advthumbnailer', 'photos']
 
 # Photos
-- 
GitLab