feat(sitemap): refactor sitemap generation to include doctors, clinics, and blogs with improved URL handling

This commit is contained in:
hamed
2026-06-21 12:52:41 +03:30
parent a8c3a57114
commit cb9d9beaab
6 changed files with 98 additions and 141 deletions
+3 -3
View File
@@ -47,7 +47,7 @@ export async function generateMetadata({ params }) {
const description =
doctor.detail ||
`رزرو نوبت آنلاین دکتر ${doctor.name}${specialtyNames ? " متخصص " + specialtyNames : ""}${doctor.address ? " | " + doctor.address : ""}`.trim();
const image = imageUrl(doctor.img) || FALLBACK_IMG;
const image = imageUrl(doctor.img?.[0]?.url) || FALLBACK_IMG;
return {
title,
@@ -103,10 +103,10 @@ async function Doctor({ params }) {
name: `دکتر ${doctor.name}`,
url: `https://www.nobat724.com/doctor/${doctor.uuid}`,
...(specialtyNames && { medicalSpecialty: specialtyNames }),
...(doctor.img && {
...(doctor.img?.[0]?.url && {
image: {
"@type": "ImageObject",
url: imageUrl(doctor.img),
url: imageUrl(doctor.img[0].url),
},
}),
...(Number(doctor.point) > 0 && {
-43
View File
@@ -1,43 +0,0 @@
const API_URL = process.env.NEXT_PUBLIC_API_URL;
const MAIN_DOMAIN = 'https://nobat724.com';
const PER_SITEMAP = 1000;
export async function generateSitemaps() {
if (!API_URL) return [{ id: 0 }];
try {
const res = await fetch(`${API_URL}/api/v1/doctors?page=1&limit=1`, {
next: { revalidate: 86400 },
});
if (!res.ok) return [{ id: 0 }];
const json = await res.json();
const total = json?.meta?.totalRecords || 0;
const pageCount = Math.max(1, Math.ceil(total / PER_SITEMAP));
return Array.from({ length: pageCount }, (_, id) => ({ id }));
} catch {
return [{ id: 0 }];
}
}
export default async function sitemap({ id }) {
if (!API_URL) return [];
try {
const res = await fetch(`${API_URL}/api/v1/doctors?page=${id + 1}&limit=${PER_SITEMAP}`, {
next: { revalidate: 3600 },
});
if (!res.ok) return [];
const json = await res.json();
const doctors = json?.data || [];
return doctors
.filter((d) => d?.uuid)
.map((d) => ({
url: `${MAIN_DOMAIN}/doctor/${d.uuid}`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8,
}));
} catch {
return [];
}
}