Files
arjmand-pharmacy/lib/media.ts
T
Alireza HassaniandCursor cd2f9dfc9d Add Arjmand Pharmacy Next.js homepage.
Initial RTL storefront with header, slider, product sections, and local image assets.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-16 17:15:14 +03:30

35 lines
871 B
TypeScript

import fs from "fs";
import path from "path";
const IMAGES_ROOT = path.join(process.cwd(), "src/assets/images");
const IMAGE_EXT = /\.(jpe?g|png|webp|gif|avif|svg)$/i;
export type Slide = {
id: string;
image: string;
href: string;
};
function listImages(subdir: string) {
const dir = path.join(IMAGES_ROOT, subdir);
if (!fs.existsSync(dir)) return [];
return fs
.readdirSync(dir)
.filter((name) => IMAGE_EXT.test(name) && !name.startsWith("."))
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
.map((file) => `/assets/images/${subdir}/${encodeURIComponent(file)}`);
}
export function getSlides(): Slide[] {
return listImages("slides").map((image, index) => ({
id: `slide-${index + 1}`,
image,
href: "#",
}));
}
export function getLogoSrc() {
return listImages("logo")[0] ?? "/placeholders/logo.svg";
}