Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streams page #303

Open
anarcat opened this issue Feb 21, 2018 · 3 comments · May be fixed by #304
Open

streams page #303

anarcat opened this issue Feb 21, 2018 · 3 comments · May be fixed by #304

Comments

@anarcat
Copy link
Contributor

anarcat commented Feb 21, 2018

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:

image

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:

image

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:

  1. 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.
  2. 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')
@saimn
Copy link
Owner

saimn commented Feb 21, 2018

The feeds plugin is currently very minimal, and can certainly be improved ;). And as the logic is very similar for the "streams page" , it should be possible to share some code between the two plugins. For instance I think the Gallery class could have a generator which would yield all images sorted by a given key (e.g. date).

the feed just gets downloaded. ;)

Maybe just a server issue? Did you test with the Python server? With a "real" server you would need to configure it to send the correct mimetype.

I blocked at the step where the Writer class expects an "Album" to write the index.html template:

I think you need a new template. I need to look at the "Writer" code to have a better idea of what you be done to make it more flexible.

Would such a plugin be merged in the first place? :)

Why not ? It seems it could be a nice feature, so I hope it will come in sigal.

`logger.info('generating streams page')`

How did you activate your plugin ? If it is not in sigal __name__ will be different and it may not inherit the logger config.

@anarcat
Copy link
Contributor Author

anarcat commented Feb 21, 2018 via email

@anarcat anarcat linked a pull request Feb 21, 2018 that will close this issue
10 tasks
@anarcat
Copy link
Contributor Author

anarcat commented Feb 21, 2018

ended up writing a prototype based on the 'flatten' approach in #304. let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants