Split landing page and album page templates

Album page templates have a single include for the landing page
template, so rendered pages remain unchanged.
This commit is contained in:
Edwin Steele
2018-03-04 14:12:04 +11:00
committed by Edwin Steele
parent 08b8e01bcf
commit e2c5d7892f
9 changed files with 42 additions and 10 deletions

View File

@@ -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)

View File

@@ -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 '''

View File

@@ -0,0 +1,2 @@
<!-- generated from album -->
{% extends "landing.html" %}

View File

@@ -0,0 +1 @@
{% extends "landing.html" %}

View File

@@ -0,0 +1,2 @@
<!-- generated from album -->
{% extends "landing.html" %}

View File

@@ -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"