From db7125f4f42bbc3e2b6f501e98b3b47a727ddc0f Mon Sep 17 00:00:00 2001 From: trecoool Date: Sat, 25 Jul 2026 21:46:44 +0200 Subject: [PATCH] Date grouping: follow the album's sort order When groupByDate was enabled the gallery re-sorted unconditionally newest-first, discarding the album.order that immich.ts had already applied. Branch the grouping sort on share.album.order so 'asc' sorts ascending, keeping the descending default for individual shares and albums with no order set. Fixes #271 --- app/src/gallery/builder.ts | 12 ++++++++---- docs/config/gallery.md | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/gallery/builder.ts b/app/src/gallery/builder.ts index 118e29e..6d25cbc 100644 --- a/app/src/gallery/builder.ts +++ b/app/src/gallery/builder.ts @@ -28,13 +28,17 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb // You can specify this in your docker-compose file via the PUBLIC_BASE_URL env var. const publicBaseUrl = process.env.PUBLIC_BASE_URL || (res.req.protocol + '://' + res.req.headers.host) - // Date grouping needs chronological order; sort newest-first when enabled - // (overrides any album.order the upstream applied). Sort by the same local - // timestamp the grouping buckets on, so buckets stay contiguous / ordered. + // Date grouping needs chronological order; follow the album's own sort + // direction, defaulting to newest-first when it has none (individual shares). + // Sort by the same local timestamp the grouping buckets on, so buckets stay + // contiguous / ordered. const groupByDate = groupByDateMode() if (groupByDate) { + const ascending = share.album?.order === 'asc' const sortKey = (a: typeof share.assets[number]) => a.localDateTime || a.fileCreatedAt || '' - share.assets.sort((a, b) => sortKey(b).localeCompare(sortKey(a))) + share.assets.sort((a, b) => ascending + ? sortKey(a).localeCompare(sortKey(b)) + : sortKey(b).localeCompare(sortKey(a))) } // Metadata display flags. Read once here and forwarded to the client via diff --git a/docs/config/gallery.md b/docs/config/gallery.md index 0488fa3..ac3d063 100644 --- a/docs/config/gallery.md +++ b/docs/config/gallery.md @@ -75,7 +75,7 @@ Group the gallery's thumbnails by date, with a header above each group. - `true` / `"month"` - month headers like "December 2024". - `"day"` - day headers like "25 December 2024". -Grouping uses each photo's local "taken" date (matching Immich's own timeline), and sorts photos newest-first. Items missing a creation date end up under an "Undated" bucket at the end (or render without any header when the whole gallery is undated). +Grouping uses each photo's local "taken" date (matching Immich's own timeline). Photos follow the album's own sort order from Immich - "Oldest first" puts the earliest group at the top, "Newest first" the most recent - and default to newest-first for shares with no album order. Items missing a creation date end up under an "Undated" bucket at the end (or render without any header when the whole gallery is undated). > [!IMPORTANT] > Requires **"Show metadata"** to be enabled on the share in Immich. When that's off, Immich strips creation dates from the assets it returns to IPP, so grouping won't work.