diff --git a/sigal/settings.py b/sigal/settings.py index 4f949e4..2d655df 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -74,6 +74,7 @@ _DEFAULT_CONFIG = { 'thumb_video_delay': '0', 'title': '', 'use_orig': False, + 'user_css': None, 'video_converter': 'ffmpeg', 'video_extensions': ['.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp'], 'video_format': 'webm', diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 04d6424..3481768 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -36,6 +36,9 @@ theme = 'galleria' # Originals will be symlinked if orig_link = True, else they will be copied. # use_orig = False +# Path to a CSS file that can be used to customize themes +# user_css = + # ---------------- # Image processing (ignored if use_orig = True) # ---------------- diff --git a/sigal/themes/colorbox/templates/base.html b/sigal/themes/colorbox/templates/base.html index f7d9073..aad8df4 100644 --- a/sigal/themes/colorbox/templates/base.html +++ b/sigal/themes/colorbox/templates/base.html @@ -11,6 +11,9 @@ + {% if settings.user_css %} + + {% endif %} {% block extra_head %}{% endblock extra_head %} {% include 'analytics.html' %} diff --git a/sigal/themes/galleria/templates/base.html b/sigal/themes/galleria/templates/base.html index c66512a..44d25ae 100644 --- a/sigal/themes/galleria/templates/base.html +++ b/sigal/themes/galleria/templates/base.html @@ -12,6 +12,9 @@ + {% if settings.user_css %} + + {% endif %} {% block extra_head %}{% endblock extra_head %} {% include 'analytics.html' %} diff --git a/sigal/themes/photoswipe/templates/base.html b/sigal/themes/photoswipe/templates/base.html index 44c683a..d26860b 100644 --- a/sigal/themes/photoswipe/templates/base.html +++ b/sigal/themes/photoswipe/templates/base.html @@ -10,6 +10,9 @@ {% block extra_head %}{% endblock extra_head %} + {% if settings.user_css %} + + {% endif %} {% include 'analytics.html' %}
diff --git a/sigal/writer.py b/sigal/writer.py index 67ef5df..ff66ee0 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -100,12 +100,19 @@ class AbstractWriter: # FIXME: use dirs_exist_ok when minimum Python is 3.8 shutil.copytree(os.path.join(self.theme, 'static'), self.theme_path) + if self.settings['user_css']: + if not os.path.exists(self.settings['user_css']): + self.logger.error('CSS file %s could not be found', + self.settings['user_css']) + else: + shutil.copy(self.settings['user_css'], self.theme_path) + def generate_context(self, album): """Generate the context dict for the given path.""" from . import __url__ as sigal_link self.logger.info("Output album : %r", album) - return { + ctx = { 'album': album, 'index_title': self.index_title, 'settings': self.settings, @@ -114,6 +121,9 @@ class AbstractWriter: 'url': url_from_path(os.path.relpath(self.theme_path, album.dst_path))}, } + if self.settings['user_css']: + ctx['user_css'] = os.path.basename(self.settings['user_css']) + return ctx def write(self, album): """Generate the HTML page and save it.""" diff --git a/tests/test_gallery.py b/tests/test_gallery.py index 3d146c2..785dcdc 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -236,12 +236,19 @@ def test_medias_sort(settings): def test_gallery(settings, tmpdir): "Test the Gallery class." + with open(str(tmpdir.join('my.css')), mode='w') as f: + f.write('color: red') + settings['destination'] = str(tmpdir) + settings['user_css'] = str(tmpdir.join('my.css')) settings['webm_options'] = ['-missing-option', 'foobar'] gal = Gallery(settings, ncpu=1) gal.build() + mycss = os.path.join(settings['destination'], 'static', 'my.css') + assert os.path.isfile(mycss) + out_html = os.path.join(settings['destination'], 'index.html') assert os.path.isfile(out_html) @@ -249,6 +256,7 @@ def test_gallery(settings, tmpdir): html = f.read() assert '