diff --git a/sigal/gallery.py b/sigal/gallery.py index d1b787c..58ccec4 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -48,7 +48,7 @@ from .utils import (Devnull, copy, check_or_create_dir, url_from_path, read_markdown, cached_property, is_valid_html5_video, get_mime) from .video import process_video -from .writer import Writer +from .writer import AlbumPageWriter, AlbumListPageWriter class Media: @@ -702,13 +702,24 @@ class Gallery(object): self.remove_files(failed_files) if self.settings['write_html']: - writer = Writer(self.settings, index_title=self.title) + album_writer = AlbumPageWriter(self.settings, index_title=self.title) + album_list_writer = AlbumListPageWriter(self.settings, index_title=self.title) with progressbar(self.albums.values(), label="%16s" % "Writing files", item_show_func=log_func, show_eta=False, file=self.progressbar_target) as albums: for album in albums: - writer.write(album) + if album.albums: + if album.medias: + self.logger.warning( + "Album %s contains sub-albums and images. " + "Please move images to their own sub-album. " + "Images in album %s will not be visible.", + album.title, album.title + ) + album_list_writer.write(album) + else: + album_writer.write(album) print('') signals.gallery_build.send(self) diff --git a/sigal/plugins/media_page.py b/sigal/plugins/media_page.py index a5a332d..25ad904 100644 --- a/sigal/plugins/media_page.py +++ b/sigal/plugins/media_page.py @@ -32,12 +32,12 @@ previous/next :class:`~sigal.gallery.Media` objects. import os from sigal import signals -from sigal.writer import Writer +from sigal.writer import AbstractWriter from sigal.utils import url_from_path from sigal.pkgmeta import __url__ as sigal_link -class PageWriter(Writer): +class PageWriter(AbstractWriter): '''A writer for writing media pages, based on writer''' template_file = "media.html" diff --git a/sigal/themes/colorbox/templates/album.html b/sigal/themes/colorbox/templates/album.html new file mode 100644 index 0000000..baadc75 --- /dev/null +++ b/sigal/themes/colorbox/templates/album.html @@ -0,0 +1,2 @@ + +{% extends "album_list.html" %} diff --git a/sigal/themes/colorbox/templates/index.html b/sigal/themes/colorbox/templates/album_list.html similarity index 100% rename from sigal/themes/colorbox/templates/index.html rename to sigal/themes/colorbox/templates/album_list.html diff --git a/sigal/themes/galleria/templates/index.html b/sigal/themes/galleria/templates/album.html similarity index 92% rename from sigal/themes/galleria/templates/index.html rename to sigal/themes/galleria/templates/album.html index a22d3da..cf422ad 100644 --- a/sigal/themes/galleria/templates/index.html +++ b/sigal/themes/galleria/templates/album.html @@ -56,20 +56,6 @@
- {% if album.albums %} -
- - -
- {% endif %} - {% if album.medias %} {% macro img_description(media) -%} {%- if media.big -%}Full size{%- endif -%} @@ -120,13 +106,7 @@ {% endif %}
- + {% include 'footer.html' %} {% if album.medias %} diff --git a/sigal/themes/galleria/templates/album_list.html b/sigal/themes/galleria/templates/album_list.html new file mode 100644 index 0000000..299d583 --- /dev/null +++ b/sigal/themes/galleria/templates/album_list.html @@ -0,0 +1,51 @@ + + + + + + + {{ album.title|striptags }} + + + + + + + + + + {% include 'gtm.html' %} +
+
+

{{ index_title }}

+ + {% if settings.links %} + + {% endif %} +
+ +
+
+ +
    + {% for alb in album.albums %} +
  • + {{ alb.name }} + {{ alb.title }} +
  • + {% endfor %} +
+
+
+ + {% include 'footer.html' %} +
+ {% include 'piwik.html' %} + + diff --git a/sigal/themes/galleria/templates/footer.html b/sigal/themes/galleria/templates/footer.html new file mode 100644 index 0000000..c1b7c68 --- /dev/null +++ b/sigal/themes/galleria/templates/footer.html @@ -0,0 +1,7 @@ + diff --git a/sigal/themes/photoswipe/templates/album.html b/sigal/themes/photoswipe/templates/album.html new file mode 100644 index 0000000..baadc75 --- /dev/null +++ b/sigal/themes/photoswipe/templates/album.html @@ -0,0 +1,2 @@ + +{% extends "album_list.html" %} diff --git a/sigal/themes/photoswipe/templates/index.html b/sigal/themes/photoswipe/templates/album_list.html similarity index 100% rename from sigal/themes/photoswipe/templates/index.html rename to sigal/themes/photoswipe/templates/album_list.html diff --git a/sigal/writer.py b/sigal/writer.py index 1424287..9e5e5b3 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -1,5 +1,6 @@ # Copyright (c) 2009-2018 - Simon Conseil # Copyright (c) 2013 - Christophe-Marie Duquesne +# Copyright (c) 2018 - Edwin Steele # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to @@ -37,10 +38,8 @@ THEMES_PATH = os.path.normpath(os.path.join( os.path.abspath(os.path.dirname(__file__)), 'themes')) -class Writer(object): - """Generate html pages for each directory of images.""" - - template_file = 'index.html' +class AbstractWriter(object): + template_file = None def __init__(self, settings, index_title=''): self.settings = settings @@ -89,7 +88,8 @@ class Writer(object): try: self.template = env.get_template(self.template_file) except TemplateNotFound: - self.logger.error('The index.html template was not found.') + self.logger.error('The template %s was not found.', + self.template_file) sys.exit(1) # Copy the theme files in the output dir @@ -118,3 +118,13 @@ class Writer(object): with open(output_file, 'w', encoding='utf-8') as f: f.write(page) + + +class AlbumListPageWriter(AbstractWriter): + """Generate an html page for a directory of albums""" + template_file = "album_list.html" + + +class AlbumPageWriter(AbstractWriter): + """Generate html pages for a directory of images.""" + template_file = "album.html"