Skip to content

Commit 4ef085c

Browse files
committed
improve discord embeds for photos
1 parent 2fa04f6 commit 4ef085c

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/pages/photos.astro

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,26 @@ try {
2424
}));
2525
2626
if (response.Contents) {
27-
photos = response.Contents
27+
const filteredPhotos = response.Contents
2828
.filter((obj: any) => obj.Key?.match(/\.(jpg|jpeg|png|gif|webp)$/i))
29-
.filter((obj: any) => !obj.Key?.startsWith("preview_"))
30-
.map((obj: any) => obj.Key!)
31-
.sort();
29+
.filter((obj: any) => !obj.Key?.startsWith("preview_"));
30+
31+
const sortedPhotos = filteredPhotos.sort((a: any, b: any) => {
32+
if (a.Metadata?.time && b.Metadata?.time) {
33+
const timeA = new Date(parseInt(a.Metadata.time) * 1000);
34+
const timeB = new Date(parseInt(b.Metadata.time) * 1000);
35+
return timeB.getTime() - timeA.getTime();
36+
}
37+
return b.Key!.localeCompare(a.Key!);
38+
});
39+
40+
console.table(sortedPhotos.map((obj: any) => ({
41+
filename: obj.Key,
42+
timestamp: obj.Metadata?.time || "NO TIME METADATA",
43+
date: obj.Metadata?.time ? new Date(parseInt(obj.Metadata.time) * 1000).toLocaleString() : "NO TIME METADATA"
44+
})));
45+
46+
photos = sortedPhotos.map((obj: any) => obj.Key!);
3247
}
3348
} catch (err) {
3449
error = "Failed to load photos!";

src/pages/photos/[slug].astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ try {
4949
error = "Failed to load photo!";
5050
}
5151
---
52-
<Page title="photos" path={"~/photos/" + photoKey}>
52+
<Page title="{photoKey}" path={"~/photos/" + photoKey}>
53+
<Fragment slot="metadata">
54+
<meta property="og:image" content={photoUrl}>
55+
</Fragment>
56+
5357
{error ? (
5458
<span class="error">{error}</span>
5559
) : photoUrl ? (

0 commit comments

Comments
 (0)