From e2c5d7892fc8d341936a142fbe82ee1c295e9f56 Mon Sep 17 00:00:00 2001 From: Edwin Steele Date: Sun, 4 Mar 2018 14:12:04 +1100 Subject: [PATCH 1/6] Split landing page and album page templates Album page templates have a single include for the landing page template, so rendered pages remain unchanged. --- sigal/gallery.py | 11 ++++++-- sigal/plugins/media_page.py | 8 ++++-- sigal/themes/colorbox/templates/album.html | 2 ++ .../templates/{index.html => landing.html} | 0 sigal/themes/galleria/templates/album.html | 1 + .../templates/{index.html => landing.html} | 0 sigal/themes/photoswipe/templates/album.html | 2 ++ .../templates/{index.html => landing.html} | 0 sigal/writer.py | 28 ++++++++++++++++--- 9 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 sigal/themes/colorbox/templates/album.html rename sigal/themes/colorbox/templates/{index.html => landing.html} (100%) create mode 100644 sigal/themes/galleria/templates/album.html rename sigal/themes/galleria/templates/{index.html => landing.html} (100%) create mode 100644 sigal/themes/photoswipe/templates/album.html rename sigal/themes/photoswipe/templates/{index.html => landing.html} (100%) diff --git a/sigal/gallery.py b/sigal/gallery.py index 324e67f..2b48d86 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, LandingPageWriter class Media: @@ -702,13 +702,18 @@ 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) + landing_page_writer = LandingPageWriter(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.path == ".": + # The special album for the top-level directory + landing_page_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..12202f4 100644 --- a/sigal/plugins/media_page.py +++ b/sigal/plugins/media_page.py @@ -32,15 +32,17 @@ 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" + @property + def template_file(self): + return "media.html" def write(self, album, media_group): ''' Generate the media page and save it ''' diff --git a/sigal/themes/colorbox/templates/album.html b/sigal/themes/colorbox/templates/album.html new file mode 100644 index 0000000..6cf317b --- /dev/null +++ b/sigal/themes/colorbox/templates/album.html @@ -0,0 +1,2 @@ + +{% extends "landing.html" %} diff --git a/sigal/themes/colorbox/templates/index.html b/sigal/themes/colorbox/templates/landing.html similarity index 100% rename from sigal/themes/colorbox/templates/index.html rename to sigal/themes/colorbox/templates/landing.html diff --git a/sigal/themes/galleria/templates/album.html b/sigal/themes/galleria/templates/album.html new file mode 100644 index 0000000..04035b6 --- /dev/null +++ b/sigal/themes/galleria/templates/album.html @@ -0,0 +1 @@ +{% extends "landing.html" %} diff --git a/sigal/themes/galleria/templates/index.html b/sigal/themes/galleria/templates/landing.html similarity index 100% rename from sigal/themes/galleria/templates/index.html rename to sigal/themes/galleria/templates/landing.html diff --git a/sigal/themes/photoswipe/templates/album.html b/sigal/themes/photoswipe/templates/album.html new file mode 100644 index 0000000..6cf317b --- /dev/null +++ b/sigal/themes/photoswipe/templates/album.html @@ -0,0 +1,2 @@ + +{% extends "landing.html" %} diff --git a/sigal/themes/photoswipe/templates/index.html b/sigal/themes/photoswipe/templates/landing.html similarity index 100% rename from sigal/themes/photoswipe/templates/index.html rename to sigal/themes/photoswipe/templates/landing.html diff --git a/sigal/writer.py b/sigal/writer.py index 1424287..98d8847 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 @@ -19,6 +20,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +import abc import jinja2 import logging import imp @@ -37,10 +39,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): + __metaclass__ = abc.ABCMeta def __init__(self, settings, index_title=''): self.settings = settings @@ -110,6 +110,10 @@ class Writer(object): album.dst_path))}, } + @abc.abstractproperty + def template_file(self): + return None + def write(self, album): """Generate the HTML page and save it.""" @@ -118,3 +122,19 @@ class Writer(object): with open(output_file, 'w', encoding='utf-8') as f: f.write(page) + + +class LandingPageWriter(AbstractWriter): + """Generate an html page for the top level directory""" + + @property + def template_file(self): + return "landing.html" + + +class AlbumPageWriter(AbstractWriter): + """Generate html pages for each directory of images.""" + + @property + def template_file(self): + return "album.html" From e8280ae6787dbc004a85fe07d857cb022d6b6cb7 Mon Sep 17 00:00:00 2001 From: Edwin Steele Date: Sun, 30 Sep 2018 21:13:03 +1000 Subject: [PATCH 2/6] Copy landing to album to clearly show diff --- sigal/themes/galleria/templates/album.html | 319 ++++++++++++++++++++- 1 file changed, 318 insertions(+), 1 deletion(-) diff --git a/sigal/themes/galleria/templates/album.html b/sigal/themes/galleria/templates/album.html index 04035b6..a22d3da 100644 --- a/sigal/themes/galleria/templates/album.html +++ b/sigal/themes/galleria/templates/album.html @@ -1 +1,318 @@ -{% extends "landing.html" %} + + + + + + + {{ album.title|striptags }} + + + + + + + + {# We will always want to show the first image when we're on an album page #} + {# Start loading now for faster document complete instead of waiting for js to load it #} + {% if album.medias %} + + {% endif %} + + {% if settings.show_map and album.show_map %} + + {% endif %} + + {% include 'analytics.html' %} + + + {% include 'gtm.html' %} +
+
+

{{ index_title }}

+ + {% if settings.links %} + + {% endif %} + + {% if album.breadcrumb %} +

+ {%- for url, title in album.breadcrumb -%} + {{ title }} + {%- if not loop.last %} » {% endif -%} + {% endfor -%} +

+
+ {% endif %} +
+ +
+ {% if album.albums %} +
+ +
    + {% for alb in album.albums %} +
  • + {{ alb.name }} + {{ alb.title }} +
  • + {% endfor %} +
+
+ {% endif %} + + {% if album.medias %} + {% macro img_description(media) -%} + {%- if media.big -%}Full size{%- endif -%} + {# clean up tags and whitespace, including newlines, in the description #} + {%- if media.description -%}
{{ media.description | striptags }}{%- endif -%} + {%- if media.exif -%} +
+ {%- if media.exif.iso -%}{{ media.exif.iso }} {%- endif -%} + {%- if media.exif.exposure -%}{{ media.exif.exposure }} {%- endif -%} + {%- if media.exif.fstop -%}{{ media.exif.fstop }} {%- endif -%} + {%- if media.exif.focal -%}{{ media.exif.focal }} {%- endif -%} +
+ {%- if media.exif.gps -%} + {{ 'N{:.6f}'.format(media.exif.gps.lat) if media.exif.gps.lat > 0 else 'S{:.6f}'.format(-media.exif.gps.lat) }}{{ 'E{:.6f}'.format(media.exif.gps.lon) if media.exif.gps.lon > 0 else 'W{:.6f}'.format(-media.exif.gps.lon) }} + {%- endif -%} + {%- if media.exif.Make or media.exif.Model -%} + {{ media.exif.Make }} {{ media.exif.Model }} + {%- endif -%} + {%- if media.exif.datetime -%} + {{ media.exif.datetime }} + {%- endif -%} + {% endif %} + {%- endmacro %} +
+ {% if settings.show_map and album.show_map %} + Show/Hide Map (m) + {% endif %} + Fullscreen (f) +
+ + {% endif %} + + {% if album.zip %} +
+

+ Download ZIP +

+
+ {% endif %} + + {% if album.description %} +
+ {{ album.description }} +
+ {% endif %} +
+ +
+

{% if album.author %}© {{ album.author }} - {% endif %} + Generated by sigal + {% if 'sigal.plugins.feeds' in settings.plugins %} + {% if settings.rss_feed %}
RSS Feed{% endif %} + {% if settings.atom_feed %}
Atom Feed{% endif %}{% endif %}

+
+
+ + {% if album.medias %} + + {% if settings.show_map and album.show_map %} + + + {% endif %} + + + + + {% endif %} + {% include 'piwik.html' %} + + From eed2e325cf67b2d83746bdb65709cfbf3faef87c Mon Sep 17 00:00:00 2001 From: Edwin Steele Date: Sun, 30 Sep 2018 21:15:57 +1000 Subject: [PATCH 3/6] Split album and landing page logic --- sigal/themes/galleria/templates/album.html | 14 - sigal/themes/galleria/templates/landing.html | 261 ------------------- 2 files changed, 275 deletions(-) diff --git a/sigal/themes/galleria/templates/album.html b/sigal/themes/galleria/templates/album.html index a22d3da..6a5d1bc 100644 --- a/sigal/themes/galleria/templates/album.html +++ b/sigal/themes/galleria/templates/album.html @@ -56,20 +56,6 @@
- {% if album.albums %} -
- -
    - {% for alb in album.albums %} -
  • - {{ alb.name }} - {{ alb.title }} -
  • - {% endfor %} -
-
- {% endif %} - {% if album.medias %} {% macro img_description(media) -%} {%- if media.big -%}Full size{%- endif -%} diff --git a/sigal/themes/galleria/templates/landing.html b/sigal/themes/galleria/templates/landing.html index a22d3da..bd70e68 100644 --- a/sigal/themes/galleria/templates/landing.html +++ b/sigal/themes/galleria/templates/landing.html @@ -12,21 +12,6 @@ - {# We will always want to show the first image when we're on an album page #} - {# Start loading now for faster document complete instead of waiting for js to load it #} - {% if album.medias %} - - {% endif %} - - {% if settings.show_map and album.show_map %} - - {% endif %} - - {% include 'analytics.html' %} {% include 'gtm.html' %} @@ -43,20 +28,9 @@ {% endif %} - - {% if album.breadcrumb %} -

- {%- for url, title in album.breadcrumb -%} - {{ title }} - {%- if not loop.last %} » {% endif -%} - {% endfor -%} -

-
- {% endif %}
- {% if album.albums %}
    @@ -68,56 +42,6 @@ {% endfor %}
- {% endif %} - - {% if album.medias %} - {% macro img_description(media) -%} - {%- if media.big -%}Full size{%- endif -%} - {# clean up tags and whitespace, including newlines, in the description #} - {%- if media.description -%}
{{ media.description | striptags }}{%- endif -%} - {%- if media.exif -%} -
- {%- if media.exif.iso -%}{{ media.exif.iso }} {%- endif -%} - {%- if media.exif.exposure -%}{{ media.exif.exposure }} {%- endif -%} - {%- if media.exif.fstop -%}{{ media.exif.fstop }} {%- endif -%} - {%- if media.exif.focal -%}{{ media.exif.focal }} {%- endif -%} -
- {%- if media.exif.gps -%} - {{ 'N{:.6f}'.format(media.exif.gps.lat) if media.exif.gps.lat > 0 else 'S{:.6f}'.format(-media.exif.gps.lat) }}{{ 'E{:.6f}'.format(media.exif.gps.lon) if media.exif.gps.lon > 0 else 'W{:.6f}'.format(-media.exif.gps.lon) }} - {%- endif -%} - {%- if media.exif.Make or media.exif.Model -%} - {{ media.exif.Make }} {{ media.exif.Model }} - {%- endif -%} - {%- if media.exif.datetime -%} - {{ media.exif.datetime }} - {%- endif -%} - {% endif %} - {%- endmacro %} -
- {% if settings.show_map and album.show_map %} - Show/Hide Map (m) - {% endif %} - Fullscreen (f) -
- - {% endif %} - - {% if album.zip %} -
-

- Download ZIP -

-
- {% endif %} - - {% if album.description %} -
- {{ album.description }} -
- {% endif %}
@@ -128,191 +52,6 @@ {% if settings.atom_feed %}
Atom Feed{% endif %}{% endif %}

- - {% if album.medias %} - - {% if settings.show_map and album.show_map %} - - - {% endif %} - - - - - {% endif %} {% include 'piwik.html' %} From be5b48d91b1a5b726a4b22083406fbedafaa631e Mon Sep 17 00:00:00 2001 From: Edwin Steele Date: Sun, 30 Sep 2018 21:42:21 +1000 Subject: [PATCH 4/6] Hoist footer into includeable file --- sigal/themes/galleria/templates/album.html | 8 +------- sigal/themes/galleria/templates/footer.html | 7 +++++++ sigal/themes/galleria/templates/landing.html | 8 +------- 3 files changed, 9 insertions(+), 14 deletions(-) create mode 100644 sigal/themes/galleria/templates/footer.html diff --git a/sigal/themes/galleria/templates/album.html b/sigal/themes/galleria/templates/album.html index 6a5d1bc..cf422ad 100644 --- a/sigal/themes/galleria/templates/album.html +++ b/sigal/themes/galleria/templates/album.html @@ -106,13 +106,7 @@ {% endif %} -
-

{% if album.author %}© {{ album.author }} - {% endif %} - Generated by sigal - {% if 'sigal.plugins.feeds' in settings.plugins %} - {% if settings.rss_feed %}
RSS Feed{% endif %} - {% if settings.atom_feed %}
Atom Feed{% endif %}{% endif %}

-
+ {% include 'footer.html' %} {% if album.medias %} 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 @@ +
+

{% if album.author %}© {{ album.author }} - {% endif %} + Generated by sigal + {% if 'sigal.plugins.feeds' in settings.plugins %} + {% if settings.rss_feed %}
RSS Feed{% endif %} + {% if settings.atom_feed %}
Atom Feed{% endif %}{% endif %}

+
diff --git a/sigal/themes/galleria/templates/landing.html b/sigal/themes/galleria/templates/landing.html index bd70e68..299d583 100644 --- a/sigal/themes/galleria/templates/landing.html +++ b/sigal/themes/galleria/templates/landing.html @@ -44,13 +44,7 @@ -
-

{% if album.author %}© {{ album.author }} - {% endif %} - Generated by sigal - {% if 'sigal.plugins.feeds' in settings.plugins %} - {% if settings.rss_feed %}
RSS Feed{% endif %} - {% if settings.atom_feed %}
Atom Feed{% endif %}{% endif %}

-
+ {% include 'footer.html' %} {% include 'piwik.html' %} From f29d57ce45543b4628a80382535a9124b842b49b Mon Sep 17 00:00:00 2001 From: Edwin Steele Date: Fri, 5 Oct 2018 17:20:27 +1000 Subject: [PATCH 5/6] Albums can only contain images or subalbums Albums containing subalbums and image will display a warning and only display the subalbums Rename landing.html template to album_list.html Stop using abstract base class Use class attribute instead of @property --- sigal/gallery.py | 16 +++++++---- sigal/themes/colorbox/templates/album.html | 2 +- .../{landing.html => album_list.html} | 0 .../{landing.html => album_list.html} | 0 sigal/themes/photoswipe/templates/album.html | 2 +- .../{landing.html => album_list.html} | 0 sigal/writer.py | 28 ++++++------------- 7 files changed, 22 insertions(+), 26 deletions(-) rename sigal/themes/colorbox/templates/{landing.html => album_list.html} (100%) rename sigal/themes/galleria/templates/{landing.html => album_list.html} (100%) rename sigal/themes/photoswipe/templates/{landing.html => album_list.html} (100%) diff --git a/sigal/gallery.py b/sigal/gallery.py index 2b48d86..8db329b 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 AlbumPageWriter, LandingPageWriter +from .writer import AlbumPageWriter, AlbumListPageWriter class Media: @@ -703,15 +703,21 @@ class Gallery(object): if self.settings['write_html']: album_writer = AlbumPageWriter(self.settings, index_title=self.title) - landing_page_writer = LandingPageWriter(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: - if album.path == ".": - # The special album for the top-level directory - landing_page_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('') diff --git a/sigal/themes/colorbox/templates/album.html b/sigal/themes/colorbox/templates/album.html index 6cf317b..baadc75 100644 --- a/sigal/themes/colorbox/templates/album.html +++ b/sigal/themes/colorbox/templates/album.html @@ -1,2 +1,2 @@ -{% extends "landing.html" %} +{% extends "album_list.html" %} diff --git a/sigal/themes/colorbox/templates/landing.html b/sigal/themes/colorbox/templates/album_list.html similarity index 100% rename from sigal/themes/colorbox/templates/landing.html rename to sigal/themes/colorbox/templates/album_list.html diff --git a/sigal/themes/galleria/templates/landing.html b/sigal/themes/galleria/templates/album_list.html similarity index 100% rename from sigal/themes/galleria/templates/landing.html rename to sigal/themes/galleria/templates/album_list.html diff --git a/sigal/themes/photoswipe/templates/album.html b/sigal/themes/photoswipe/templates/album.html index 6cf317b..baadc75 100644 --- a/sigal/themes/photoswipe/templates/album.html +++ b/sigal/themes/photoswipe/templates/album.html @@ -1,2 +1,2 @@ -{% extends "landing.html" %} +{% extends "album_list.html" %} diff --git a/sigal/themes/photoswipe/templates/landing.html b/sigal/themes/photoswipe/templates/album_list.html similarity index 100% rename from sigal/themes/photoswipe/templates/landing.html rename to sigal/themes/photoswipe/templates/album_list.html diff --git a/sigal/writer.py b/sigal/writer.py index 98d8847..9e5e5b3 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -1,6 +1,6 @@ # Copyright (c) 2009-2018 - Simon Conseil # Copyright (c) 2013 - Christophe-Marie Duquesne -# Copyright (c) 2018 - Edwin Steele +# 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 @@ -20,7 +20,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -import abc import jinja2 import logging import imp @@ -40,7 +39,7 @@ THEMES_PATH = os.path.normpath(os.path.join( class AbstractWriter(object): - __metaclass__ = abc.ABCMeta + template_file = None def __init__(self, settings, index_title=''): self.settings = settings @@ -89,7 +88,8 @@ class AbstractWriter(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 @@ -110,10 +110,6 @@ class AbstractWriter(object): album.dst_path))}, } - @abc.abstractproperty - def template_file(self): - return None - def write(self, album): """Generate the HTML page and save it.""" @@ -124,17 +120,11 @@ class AbstractWriter(object): f.write(page) -class LandingPageWriter(AbstractWriter): - """Generate an html page for the top level directory""" - - @property - def template_file(self): - return "landing.html" +class AlbumListPageWriter(AbstractWriter): + """Generate an html page for a directory of albums""" + template_file = "album_list.html" class AlbumPageWriter(AbstractWriter): - """Generate html pages for each directory of images.""" - - @property - def template_file(self): - return "album.html" + """Generate html pages for a directory of images.""" + template_file = "album.html" From 8f4c31c8860755fea2587cd1bb44a23ea93e9441 Mon Sep 17 00:00:00 2001 From: Edwin Steele Date: Tue, 9 Oct 2018 16:48:51 +1100 Subject: [PATCH 6/6] Use class attribute instead of @property --- sigal/plugins/media_page.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sigal/plugins/media_page.py b/sigal/plugins/media_page.py index 12202f4..25ad904 100644 --- a/sigal/plugins/media_page.py +++ b/sigal/plugins/media_page.py @@ -40,9 +40,7 @@ from sigal.pkgmeta import __url__ as sigal_link class PageWriter(AbstractWriter): '''A writer for writing media pages, based on writer''' - @property - def template_file(self): - return "media.html" + template_file = "media.html" def write(self, album, media_group): ''' Generate the media page and save it '''