diff --git a/src/app/(routes)/blog/categories/page.tsx b/src/app/(routes)/blog/categories/page.tsx index 37d8e13..5971302 100644 --- a/src/app/(routes)/blog/categories/page.tsx +++ b/src/app/(routes)/blog/categories/page.tsx @@ -11,6 +11,7 @@ import { Metadata } from "next"; import { getDictionary } from "@/app/lib/functions/dictionaries"; import { getDefaultLocale } from "@/app/lib/functions/utils"; import { ogImageUrl, SITE_NAME, SITE_URL } from "@/app/lib/site-config"; +import { getCategoryImageSrc } from "@/app/lib/category-image"; const TITLE = "All Categories List"; const DESCRIPTION = @@ -90,7 +91,7 @@ export default async function Categories(props: categoryPropsType) { > {`${category.name}
{`${category.name} = { + // English slugs + "frontend-development": "/images/categories/frontend-development.webp", + "react-nextjs": "/images/categories/react-nextjs.webp", + "backend-development": "/images/categories/backend-development.webp", + "devops-deployment": "/images/categories/devops-deployment.webp", + "programming-careers": "/images/categories/programming-careers.webp", + "web-performance-seo": "/images/categories/web-performance-seo.webp", + "engineering-practices": "/images/categories/engineering-practices.webp", + + // Persian slugs + "frontend-fa": "/images/categories/frontend-development.webp", + "react-nextjs-fa": "/images/categories/react-nextjs.webp", + "backend-fa": "/images/categories/backend-development.webp", + "devops-fa": "/images/categories/devops-deployment.webp", + "career-fa": "/images/categories/programming-careers.webp", + "web-performance-seo-fa": "/images/categories/web-performance-seo.webp", + "engineering-practices-fa": "/images/categories/engineering-practices.webp", +}; + +/** + * Returns the best image source for a blog category. + * If the category has a valid remote/local image, uses it. + * Otherwise, maps the category slug (with or without -fa) to the static webp illustration. + */ +export function getCategoryImageSrc(slug: string, image?: string | null): string { + if (image && typeof image === "string" && image.trim() !== "") { + return image.trim(); + } + + const cleanSlug = slug.trim().toLowerCase(); + + if (CATEGORY_IMAGE_MAP[cleanSlug]) { + return CATEGORY_IMAGE_MAP[cleanSlug]; + } + + const baseSlug = cleanSlug.replace(/-fa$/, ""); + if (CATEGORY_IMAGE_MAP[baseSlug]) { + return CATEGORY_IMAGE_MAP[baseSlug]; + } + + // Fallback to engineering practices illustration + return "/images/categories/engineering-practices.webp"; +}