plugin/photos: add support to skip gallery
Control whether to exclude from the build some photo gallery or them all.
PELICAN_PHOTO_EXCLUDE and PELICAN_PHOTO_EXCLUDEALL can be set in the
environment. The former is a whitespace separated list of directory
_basename_s, the latter is a binary 0 or 1.
Note: when excluding galleries, pelican will still generate html files
accounting for photos, so it is possible to defer processing images and
installing them separately from the html.
i.e.
PELICAN_PHOTO_EXCLUDE="gallery1 gallery9"
or
PELICAN_PHOTO_EXCLUDEALL="1"
diff --git a/pelicanconf.py b/pelicanconf.py
index 64fdeee..c20ed3d 100644
--- a/pelicanconf.py
+++ b/pelicanconf.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
+import os
# For an exhaustive list of available variables and how to use them refer to
# http://docs.getpelican.com/en/stable/settings.html
@@ -207,7 +208,9 @@
DAY_ARCHIVE_URL = ''
# Gallery plugin
-PHOTO_LIBRARY = '/home/luigi/giggi.me.c/multimedia/gallery'
+PHOTO_LIBRARY = os.getenv('PELICAN_PHOTO_LIBRARY')
+PHOTO_EXCLUDE = os.getenv('PELICAN_PHOTO_EXCLUDE')
+PHOTO_EXCLUDEALL = os.getenv('PELICAN_PHOTO_EXCLUDEALL')
PHOTO_GALLERY = (2000, 1333, 100)
PHOTO_ARTICLE = (2000, 1333, 100)
PHOTO_THUMB = (300, 200, 100)
diff --git a/theme/plugins/photos/photos.py b/theme/plugins/photos/photos.py
index d0c1af1..551bdf6 100644
--- a/theme/plugins/photos/photos.py
+++ b/theme/plugins/photos/photos.py
@@ -62,6 +62,8 @@
DEFAULT_CONFIG.setdefault('PHOTO_EXIF_COPYRIGHT_AUTHOR', DEFAULT_CONFIG['SITENAME'])
DEFAULT_CONFIG.setdefault('PHOTO_LIGHTBOX_GALLERY_ATTR', 'data-lightbox')
DEFAULT_CONFIG.setdefault('PHOTO_LIGHTBOX_CAPTION_ATTR', 'data-title')
+ DEFAULT_CONFIG.setdefault('PHOTO_EXCLUDE', [])
+ DEFAULT_CONFIG.setdefault('PHOTO_EXCLUDEALL', False)
DEFAULT_CONFIG['queue_resize'] = {}
DEFAULT_CONFIG['created_galleries'] = {}
@@ -89,6 +91,10 @@
pelican.settings.setdefault('PHOTO_EXIF_COPYRIGHT_AUTHOR', pelican.settings['AUTHOR'])
pelican.settings.setdefault('PHOTO_LIGHTBOX_GALLERY_ATTR', 'data-lightbox')
pelican.settings.setdefault('PHOTO_LIGHTBOX_CAPTION_ATTR', 'data-title')
+ # Need to change type, PHOTO_EXCLUDE must be iterable
+ if pelican.settings['PHOTO_EXCLUDE'] is None:
+ pelican.settings['PHOTO_EXCLUDE'] = []
+ pelican.settings['PHOTO_EXCLUDEALL'] = pelican.settings['PHOTO_EXCLUDEALL'] == '1'
def read_notes(filename, msg=None):
@@ -290,6 +296,10 @@
def resize_photos(generator, writer):
+ if generator.settings['PHOTO_EXCLUDEALL']:
+ logger.warning('photos: Skip all galleries')
+ return
+
if generator.settings['PHOTO_RESIZE_JOBS'] == -1:
debug = True
generator.settings['PHOTO_RESIZE_JOBS'] = 1
@@ -300,6 +310,13 @@
logger.debug('Debug Status: {}'.format(debug))
for resized, what in DEFAULT_CONFIG['queue_resize'].items():
resized = os.path.join(generator.output_path, resized)
+ abs_path = os.path.split(resized)[0]
+ basename = os.path.basename(abs_path)
+
+ if basename in generator.settings['PHOTO_EXCLUDE']:
+ logger.warning('photos: Skip gallery: {}'.format(basename))
+ continue
+
orig, spec = what
if (not os.path.isfile(resized) or os.path.getmtime(orig) > os.path.getmtime(resized)):
if debug: