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>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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";
|
||||
}
|
||||
Reference in New Issue
Block a user