Merge pull request #343 from edwinsteele/feature/split-index-album-templates

Split landing page and album templates
This commit is contained in:
Simon Conseil
2018-10-09 09:36:22 +02:00
committed by GitHub
10 changed files with 94 additions and 31 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, 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)

View File

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

View File

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

View File

@@ -56,20 +56,6 @@
</header>
<div id="main" role="main">
{% if album.albums %}
<div id="albums">
<!-- <h1>Albums</h1> -->
<ul>
{% for alb in album.albums %}
<li><a href="{{ alb.url }}">
<img src="{{ alb.thumbnail }}" class="album_thumb" alt="{{ alb.name }}" title="{{ alb.name }}" /></a>
<span class="album_title">{{ alb.title }}</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if album.medias %}
{% macro img_description(media) -%}
{%- if media.big -%}<a href='{{ media.big }}'>Full size</a>{%- endif -%}
@@ -120,13 +106,7 @@
{% endif %}
</div>
<footer>
<p>{% if album.author %}&copy; {{ album.author }} - {% endif %}
Generated by <a href="{{ sigal_link }}">sigal</a>
{% if 'sigal.plugins.feeds' in settings.plugins %}
{% if settings.rss_feed %}<br><a href={{ settings.rss_feed.feed_url }}>RSS Feed</a>{% endif %}
{% if settings.atom_feed %}<br><a href={{ settings.atom_feed.feed_url }}>Atom Feed</a>{% endif %}{% endif %}</p>
</footer>
{% include 'footer.html' %}
</div>
{% if album.medias %}

View File

@@ -0,0 +1,51 @@
<!doctype html>
<html lang="{{ settings.html_language }}">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{ album.title|striptags }}</title>
<meta name="description" content="">
<meta name="author" content="{{ album.author }}">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="{{ theme.url }}/css/normalize.css">
<link rel="stylesheet" href="{{ theme.url }}/themes/classic/galleria.classic.css">
<link rel="stylesheet" href="{{ theme.url }}/css/style.css">
</head>
<body>
{% include 'gtm.html' %}
<div class="container">
<header>
<h1><a href="{{ album.index_url }}">{{ index_title }}</a></h1>
{% if settings.links %}
<nav id="menu">
<ul>
{% for title, link in settings.links %}
<li><a href="{{ link }}">{{ title }}</a></li>
{% endfor %}
</ul>
</nav>
{% endif %}
</header>
<div id="main" role="main">
<div id="albums">
<!-- <h1>Albums</h1> -->
<ul>
{% for alb in album.albums %}
<li><a href="{{ alb.url }}">
<img src="{{ alb.thumbnail }}" class="album_thumb" alt="{{ alb.name }}" title="{{ alb.name }}" /></a>
<span class="album_title">{{ alb.title }}</span>
</li>
{% endfor %}
</ul>
</div>
</div>
{% include 'footer.html' %}
</div>
{% include 'piwik.html' %}
</body>
</html>

View File

@@ -0,0 +1,7 @@
<footer>
<p>{% if album.author %}&copy; {{ album.author }} - {% endif %}
Generated by <a href="{{ sigal_link }}">sigal</a>
{% if 'sigal.plugins.feeds' in settings.plugins %}
{% if settings.rss_feed %}<br><a href={{ settings.rss_feed.feed_url }}>RSS Feed</a>{% endif %}
{% if settings.atom_feed %}<br><a href={{ settings.atom_feed.feed_url }}>Atom Feed</a>{% endif %}{% endif %}</p>
</footer>

View File

@@ -0,0 +1,2 @@
<!-- generated from album -->
{% extends "album_list.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
@@ -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"