From 9aeef7814ce86bba8d22e9f6c3903c280b0d1732 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Wed, 19 Jun 2024 21:15:08 +0200 Subject: group mode: sort depending on whether a user clicks prev/next --- bin/pyggle | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/bin/pyggle b/bin/pyggle index 0a88a4a..5f41b27 100755 --- a/bin/pyggle +++ b/bin/pyggle @@ -667,18 +667,22 @@ def copy_files(base_dir): def write_gallery( - file_buf, filename, thumbnails, group=None, files=list(), this_file=None + file_buf, + filename, + thumbnails, + group=None, + this_file=None, + prev_file=None, + next_file=None, ): - if files: + if prev_file or next_file: nav_buf = '" file_buf += nav_buf @@ -689,7 +693,14 @@ def write_gallery( prev_heading = thumbnail.group_key file_buf += thumbnail.to_html(i, args.with_detail_page) - if files: + if prev_file or next_file: + nav_buf = '" file_buf += nav_buf with open(f"{base_dir}/share/html_end", "r") as f: @@ -962,12 +973,26 @@ if __name__ == "__main__": if args.group_files != "none": thumbnail_keys = list(sorted(set(map(lambda t: t.file_key, thumbnails)))) - for thumbnail_key in thumbnail_keys: + for i, thumbnail_key in enumerate(thumbnail_keys): + prev_key = i > 0 and thumbnail_keys[i - 1] or None + next_key = i + 1 < len(thumbnail_keys) and thumbnail_keys[i + 1] or None write_gallery( html_buf, f"{thumbnail_key}.html", list(filter(lambda t: t.file_key == thumbnail_key, thumbnails)), group=args.group, - files=thumbnail_keys, this_file=thumbnail_key, + prev_file=prev_key, + next_file=next_key, + ) + write_gallery( + html_buf, + f"{thumbnail_key}-r.html", + reversed( + list(filter(lambda t: t.file_key == thumbnail_key, thumbnails)) + ), + group=args.group, + this_file=thumbnail_key, + prev_file=prev_key, + next_file=next_key, ) -- cgit v1.2.3