f**k ahh syling and gallery work

This commit is contained in:
Aria 2025-04-25 04:23:45 +10:00
parent 3bf39af153
commit eedba4c364
19 changed files with 165 additions and 19 deletions

20
src/utils/albums.ts Normal file
View file

@ -0,0 +1,20 @@
export async function getAlbumImages(albumId: string) {
// 1. List all album files from collections path
let images = import.meta.glob<{ default: ImageMetadata }>(
"/src/content/albums/**/*.{jpeg,jpg,webp,avif,png,jxl}"
);
// 2. Filter images by albumId
images = Object.fromEntries(
Object.entries(images).filter(([key]) => key.includes(albumId))
);
// 3. Images are promises, so we need to resolve the glob promises
const resolvedImages = await Promise.all(
Object.values(images).map((image) => image().then((mod) => mod.default))
);
// 4. Shuffle images in random order
resolvedImages.sort(() => Math.random() - 0.5);
return resolvedImages;
}