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"