feat(clinic): enhance generateMetadata and JSON-LD for comprehensive clinic schema
This commit is contained in:
@@ -32,15 +32,24 @@ export async function generateMetadata({ params }) {
|
||||
const title = `${clinic.title} | ${siteName}`;
|
||||
const description = `رزرو نوبت و اطلاعات ${clinic.title}. مشاهده لیست پزشکان و خدمات درمانی موجود.`;
|
||||
|
||||
const image = clinic.images_clinic?.[0]?.url
|
||||
? [imageUrl(clinic.images_clinic[0].url)]
|
||||
: ["https://www.nobat724.com/assets/images/logo.png"];
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
images: clinic.images_clinic?.[0]?.url
|
||||
? [imageUrl(clinic.images_clinic[0].url)]
|
||||
: ["https://www.nobat724.com/assets/images/logo.png"],
|
||||
type: "website",
|
||||
images: image,
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title,
|
||||
description,
|
||||
images: image,
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
@@ -48,6 +57,19 @@ export async function generateMetadata({ params }) {
|
||||
}
|
||||
}
|
||||
|
||||
function computeClinicRating(doctors) {
|
||||
const rated = doctors.filter((d) => d.point && Number(d.point) > 0);
|
||||
if (rated.length === 0) return null;
|
||||
const avg = rated.reduce((sum, d) => sum + Number(d.point), 0) / rated.length;
|
||||
return {
|
||||
"@type": "AggregateRating",
|
||||
ratingValue: avg.toFixed(1),
|
||||
ratingCount: rated.length,
|
||||
bestRating: "5",
|
||||
worstRating: "1",
|
||||
};
|
||||
}
|
||||
|
||||
async function Clinic({ params, searchParams }) {
|
||||
const { slug } = await params;
|
||||
const sp = await searchParams;
|
||||
@@ -65,14 +87,61 @@ async function Clinic({ params, searchParams }) {
|
||||
? { current: meta.currentPage, total_pages: meta.totalPages }
|
||||
: { current: 1, total_pages: 1 };
|
||||
|
||||
const aggregateRating = computeClinicRating(doctors);
|
||||
|
||||
const specialties = [
|
||||
...new Set(
|
||||
doctors.flatMap((d) => d.specialties?.map((s) => s.name) ?? [])
|
||||
),
|
||||
].slice(0, 5);
|
||||
|
||||
const sameAsLinks = clinic?.social_media
|
||||
? Object.values(clinic.social_media).filter(Boolean)
|
||||
: [];
|
||||
|
||||
const jsonLd = clinic
|
||||
? {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "MedicalClinic",
|
||||
name: clinic.title,
|
||||
url: `https://www.nobat724.com/clinic/${clinic.uuid}`,
|
||||
...(clinic.images_clinic?.[0]?.url && {
|
||||
image: imageUrl(clinic.images_clinic[0].url),
|
||||
image: {
|
||||
"@type": "ImageObject",
|
||||
url: imageUrl(clinic.images_clinic[0].url),
|
||||
name: clinic.title,
|
||||
},
|
||||
}),
|
||||
...(clinic.phone && { telephone: clinic.phone }),
|
||||
...(clinic.location && {
|
||||
address: {
|
||||
"@type": "PostalAddress",
|
||||
streetAddress: clinic.location,
|
||||
addressCountry: "IR",
|
||||
},
|
||||
}),
|
||||
...(clinic.map?.latitude && clinic.map?.longitude && {
|
||||
geo: {
|
||||
"@type": "GeoCoordinates",
|
||||
latitude: clinic.map.latitude,
|
||||
longitude: clinic.map.longitude,
|
||||
},
|
||||
hasMap: `https://maps.google.com/?q=${clinic.map.latitude},${clinic.map.longitude}`,
|
||||
}),
|
||||
...(clinic["24_7"] && {
|
||||
openingHoursSpecification: {
|
||||
"@type": "OpeningHoursSpecification",
|
||||
dayOfWeek: [
|
||||
"Monday", "Tuesday", "Wednesday", "Thursday",
|
||||
"Friday", "Saturday", "Sunday",
|
||||
],
|
||||
opens: "00:00",
|
||||
closes: "23:59",
|
||||
},
|
||||
}),
|
||||
...(aggregateRating && { aggregateRating }),
|
||||
...(specialties.length > 0 && { medicalSpecialty: specialties }),
|
||||
...(sameAsLinks.length > 0 && { sameAs: sameAsLinks }),
|
||||
}
|
||||
: null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user