f**k ahh syling and gallery work
This commit is contained in:
parent
3bf39af153
commit
eedba4c364
19 changed files with 165 additions and 19 deletions
20
src/utils/albums.ts
Normal file
20
src/utils/albums.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue