fix: display placeholder image if no blog post cover image is present

This commit is contained in:
Dorian Niemiec 2024-09-07 13:30:30 +02:00
parent 3feba5be25
commit 62d5ccbb6d
3 changed files with 31 additions and 21 deletions

View file

@ -64,7 +64,9 @@ export async function generateMetadata({
type: "website", type: "website",
images: [ images: [
{ {
url: urlFor(data.titleImage).url(), url: data.titleImage
? urlFor(data.titleImage).url()
: "/blog-missing.png",
width: 800, width: 800,
height: 600, height: 600,
alt: `${data.title} - SVR.JS` alt: `${data.title} - SVR.JS`
@ -76,7 +78,9 @@ export async function generateMetadata({
site: "@SVR_JS", site: "@SVR_JS",
title: `${data.title} - SVR.JS`, title: `${data.title} - SVR.JS`,
description: data.smallDescription, description: data.smallDescription,
images: [urlFor(data.titleImage).url()], images: [
data.titleImage ? urlFor(data.titleImage).url() : "/blog-missing.png"
],
creator: "@SVR_JS" creator: "@SVR_JS"
} }
}; };
@ -172,13 +176,16 @@ export default async function BlogSlugArticle({
</Link> </Link>
</div> </div>
<header className="text-start mb-8 w-full"> <header className="text-start mb-8 w-full">
{data.titleImage && (
<div className="mb-2"> <div className="mb-2">
<h1 className="text-3xl md:text-5xl mb-8 py-4 font-bold text-black dark:bg-clip-text dark:text-transparent dark:bg-gradient-to-b dark:from-white dark:to-neutral-400"> <h1 className="text-3xl md:text-5xl mb-8 py-4 font-bold text-black dark:bg-clip-text dark:text-transparent dark:bg-gradient-to-b dark:from-white dark:to-neutral-400">
{data.title} {data.title}
</h1> </h1>
<Image <Image
src={urlFor(data.titleImage).url()} src={
data.titleImage
? urlFor(data.titleImage).url()
: "/blog-missing.png"
}
alt={data.title} alt={data.title}
width={1200} width={1200}
height={800} height={800}
@ -189,7 +196,6 @@ export default async function BlogSlugArticle({
Uploaded at {formattedDate} Uploaded at {formattedDate}
</p> </p>
</div> </div>
)}
</header> </header>
<Separator className="mb-6" /> <Separator className="mb-6" />
<article className="prose max-w-full md:prose-lg dark:prose-invert"> <article className="prose max-w-full md:prose-lg dark:prose-invert">

View file

@ -68,7 +68,11 @@ const BlogCards: React.FC<BlogCardsProps> = async ({ searchParams }) => {
<Link href={`/blog/${post.currentSlug}`} className="block"> <Link href={`/blog/${post.currentSlug}`} className="block">
<div className="relative overflow-hidden rounded-t-lg"> <div className="relative overflow-hidden rounded-t-lg">
<Image <Image
src={urlFor(post.titleImage).url()} src={
post.titleImage
? urlFor(post.titleImage).url()
: "/blog-missing.png"
}
alt={post.title} alt={post.title}
width={500} width={500}
height={300} height={300}

BIN
public/blog-missing.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB