-
Notifications
You must be signed in to change notification settings - Fork 170
streams page #303
Description
Hi!
I've brought this idea up on IRC, but figured it would be more productive to discuss this formally here. :) I'd like to have a way to show the user all the recent images in the gallery. I know that the feeds plugin can somewhat do that, and even that many browsers will display that page somewhat cleanly. But it's really sub-optimal. In Firefox 58:
First, the summary on top is all wrong: it should be HTML formatted, and instead it's one giant blob of text. Then the most important problem: the images are not clickable, which is also a bug in the feeds plugin (one which I'll get into later i guess)...
In Chromium, it looks like this:
ie. the feed just gets downloaded. ;) There are apparently some workarounds for fixing that, but they mostly consist of trying to make Chrome fire up the right RSS feed reader rather than parsing the RSS feed itself (which is silly: RSS is just XML like HTML is, and should be parsable by chrome natively, but whatever).
So we could try to fight that silly battle of making web browsers respect standards, but I doubt we'll go anywhere with that. Which brings me to the idea of writing a "streams" plugin.
I started looking into that, and I've got to the point of writing a stub plugin to get my hands dirty with the mechanics of that. I blocked at the step where the Writer class expects an "Album" to write the index.html template:
# -*- coding: utf-8 -*-
"""Plugin which adds a "stream page" listing all images.
This plugin is similar to the feeds plugin in that it allows listing
images in (reverse) chronological order, to show the most recent
ones. This allows users to browse the gallery as a "flat" list of
images, a bit like you would on sites like Flickr or Instagram.
Settigns:
- ``stream_page``, see below
Example::
stream_page = { 'name': 'stream', 'nb_items': 10, 'title': 'Stream' }
In the above example, a 10-item page will be created at
/stream.html. If any entry is missing, a default will be used as
defined above (except `nb_items` which defaults to no limit.
.. todo:: What happens if an album with the same name exists?
"""
import logging
from sigal import signals
from sigal.writer import Writer
logger = logging.getLogger(__name__)
def generate_stream(gallery):
logger.info('generating streams page')
# copy-pasted from feeds.py
medias = [med for album in gallery.albums.values()
for med in album.medias if med.date is not None]
medias.sort(key=lambda m: m.date, reverse=True)
settings = gallery.settings['stream_page']
writer = Writer(gallery.settings,
index_title=settings.get('title', 'Stream'))
writer.write(medias) # XXX: obviously doesn't work
def register(settings):
signals.gallery_build.connect(generate_stream)so here i'm looking for advice of where I should go. I can think of two possibilities:
- write an Album.flatten() function that would somehow regroup all media in one given album in one mega-album. this would have the advantage of allowing the "stream" page to be created per album somehow.
- just bypass the Writer altogether and feed the right elements to the Jinja template directly. that seems like the easiest way, but doesn't favor code reuse and makes this yet another little precious snowflake.
What do you think?
Would such a plugin be merged in the first place? :)
PS: another problem I have mentioned on IRC with my plugin is that this line doesn't yield any output, I'm not sure why:
logger.info('generating streams page')
