aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 12:41:54 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 12:41:54 +0530
commit52d4c41a25d15f050a4a094281cedddca56ed6a0 (patch)
tree84f6fd41d643e37f07440726a754a42da7f8a49d /internal
parent5fa3daffb2f29b10828c4103b9b2b78220568736 (diff)
downloadgalleryd-52d4c41a25d15f050a4a094281cedddca56ed6a0.tar.xz
galleryd-52d4c41a25d15f050a4a094281cedddca56ed6a0.zip
feat(gallery): sort photos by capture data
Diffstat (limited to 'internal')
-rw-r--r--internal/gallery/builder.go2
-rw-r--r--internal/gallery/sort.go17
2 files changed, 19 insertions, 0 deletions
diff --git a/internal/gallery/builder.go b/internal/gallery/builder.go
index 60ba006..8e7583a 100644
--- a/internal/gallery/builder.go
+++ b/internal/gallery/builder.go
@@ -43,5 +43,7 @@ func (b *Builder) Build(
})
}
+ sortPhotos(photos)
+
return photos, nil
}
diff --git a/internal/gallery/sort.go b/internal/gallery/sort.go
new file mode 100644
index 0000000..6c97ee3
--- /dev/null
+++ b/internal/gallery/sort.go
@@ -0,0 +1,17 @@
+package gallery
+
+import "sort"
+
+// sortPhotos orders photos by date taken (newest first).
+//
+// Photos with identical timestamps are ordered by relative path to
+// provide deterministic output.
+func sortPhotos(photos []Photo) {
+ sort.SliceStable(photos, func(i, j int) bool {
+ if !photos[i].DateTaken.Equal(photos[j].DateTaken) {
+ return photos[i].DateTaken.After(photos[j].DateTaken)
+ }
+
+ return photos[i].RelativePath < photos[j].RelativePath
+ })
+}