fix(blog): ensure Persian category slugs resolve to valid category illustrations
Deploy Frontend / deploy (push) Successful in 1m8s
Deploy Frontend / deploy (push) Successful in 1m8s
This commit is contained in:
1 parent
0d6aaa10c8
commit
e7bfd6b068
3 files changed
+48
-2
No files matched your search
@@ -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) {
|
||||
>
|
||||
<Image
|
||||
className="max-w-[50%] rounded-md object-cover"
|
||||
src={category.image || `/images/categories/${category.slug.replace(/-fa$/, "")}.webp`}
|
||||
src={getCategoryImageSrc(category.slug, category.image)}
|
||||
alt={`${category.name} category image`}
|
||||
loading="lazy"
|
||||
width={350}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { CategoryType } from "@/app/types/types";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { ArrowLeft, ArrowRight } from "lucide-react";
|
||||
import { getCategoryImageSrc } from "@/app/lib/category-image";
|
||||
|
||||
interface CategoriesProps {
|
||||
data: CategoryType[];
|
||||
@@ -44,7 +45,7 @@ export default async function Categories({ data }: CategoriesProps) {
|
||||
>
|
||||
<div className="relative w-full aspect-square overflow-hidden rounded-xl bg-muted">
|
||||
<Image
|
||||
src={category.image || `/images/categories/${category.slug.replace(/-fa$/, "")}.webp`}
|
||||
src={getCategoryImageSrc(category.slug, category.image)}
|
||||
alt={`${category.name} category`}
|
||||
fill
|
||||
className="object-cover transition-transform duration-500 group-hover:scale-105"
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
const CATEGORY_IMAGE_MAP: Record<string, string> = {
|
||||
// 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";
|
||||
}
|
||||
Reference in new issue
Block a user