Add media carousel section to homepage
Display past event photos in an auto-playing carousel between the "What is Spanglish?" and "Stay Updated" sections. Images are loaded dynamically from /images/carrousel/ folder with support for jpg, png, and webp formats.
This commit is contained in:
37
frontend/src/lib/carouselImages.ts
Normal file
37
frontend/src/lib/carouselImages.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export interface CarouselImage {
|
||||
src: string;
|
||||
alt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all images from the carrousel folder at build/request time.
|
||||
* Supports jpg, jpeg, png, webp, and gif formats.
|
||||
*/
|
||||
export function getCarouselImages(): CarouselImage[] {
|
||||
const carrouselDir = path.join(process.cwd(), 'public', 'images', 'carrousel');
|
||||
|
||||
try {
|
||||
const files = fs.readdirSync(carrouselDir);
|
||||
|
||||
// Filter for supported image formats
|
||||
const supportedExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.gif'];
|
||||
const imageFiles = files.filter((file) => {
|
||||
const ext = path.extname(file).toLowerCase();
|
||||
return supportedExtensions.includes(ext);
|
||||
});
|
||||
|
||||
// Sort by filename (which includes date) for consistent ordering
|
||||
imageFiles.sort();
|
||||
|
||||
return imageFiles.map((file) => ({
|
||||
src: `/images/carrousel/${file}`,
|
||||
alt: 'Spanglish language exchange event moment',
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Error reading carrousel directory:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user