feat(doctor): enhance doctor schema with addresses, ratings, and social media links
feat(robots): update disallow rules to include '/panel' feat(sitemap): implement separate sitemaps for doctors, clinics, and blogs feat(icons): add social media icons for doctor profiles
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
const MAIN_DOMAIN = 'https://nobat724.com';
|
||||
const PER_SITEMAP = 1000;
|
||||
|
||||
function toSafeDate(value) {
|
||||
if (!value) return new Date();
|
||||
const d = new Date(value);
|
||||
return isNaN(d.getTime()) ? new Date() : d;
|
||||
}
|
||||
|
||||
export async function generateSitemaps() {
|
||||
if (!API_URL) return [{ id: 0 }];
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/v1/blogs?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/blogs?page=${id + 1}&limit=${PER_SITEMAP}`, {
|
||||
next: { revalidate: 3600 },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const json = await res.json();
|
||||
const blogs = json?.data || [];
|
||||
return blogs
|
||||
.filter((b) => b?.slug || b?.uuid)
|
||||
.map((b) => ({
|
||||
url: `${MAIN_DOMAIN}/blog/${b.slug || b.uuid}`,
|
||||
lastModified: toSafeDate(b.created),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.6,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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/clinics?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/clinics?page=${id + 1}&limit=${PER_SITEMAP}`, {
|
||||
next: { revalidate: 3600 },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const json = await res.json();
|
||||
const clinics = json?.data || [];
|
||||
return clinics
|
||||
.filter((c) => c?.uuid)
|
||||
.map((c) => ({
|
||||
url: `${MAIN_DOMAIN}/clinic/${c.uuid}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.7,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,19 @@ const getDoctor = cache(async (slug) => {
|
||||
}
|
||||
});
|
||||
|
||||
const getDoctorAddresses = cache(async (doctorId) => {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/v1/clinic-pro/doctor-addresses/${doctorId}`, {
|
||||
next: { revalidate: 3600, tags: [`doctor-addresses-${doctorId}`] },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const json = await res.json();
|
||||
return json?.data ?? [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
export async function generateMetadata({ params }) {
|
||||
const { slug } = await params;
|
||||
const { matchedCity } = await getStateInfo();
|
||||
@@ -79,20 +92,60 @@ async function Doctor({ params }) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
const addresses = doctor ? await getDoctorAddresses(doctor.id) : [];
|
||||
|
||||
const specialtyNames = doctor?.specialties?.map((s) => s.name).join(" و ") || "";
|
||||
const jsonLd = doctor
|
||||
? {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Physician",
|
||||
"@id": `https://www.nobat724.com/doctor/${doctor.uuid}#physician`,
|
||||
name: `دکتر ${doctor.name}`,
|
||||
url: `https://www.nobat724.com/doctor/${doctor.uuid}`,
|
||||
...(specialtyNames && { medicalSpecialty: specialtyNames }),
|
||||
...(doctor.img && { image: doctor.img }),
|
||||
...(doctor.address && {
|
||||
address: {
|
||||
"@type": "PostalAddress",
|
||||
streetAddress: doctor.address,
|
||||
...(doctor.img && {
|
||||
image: {
|
||||
"@type": "ImageObject",
|
||||
url: imageUrl(doctor.img),
|
||||
},
|
||||
}),
|
||||
...(Number(doctor.point) > 0 && {
|
||||
aggregateRating: {
|
||||
"@type": "AggregateRating",
|
||||
ratingValue: doctor.point,
|
||||
bestRating: "5",
|
||||
ratingCount: comments?.length || 1,
|
||||
},
|
||||
}),
|
||||
...(comments?.length > 0 && {
|
||||
review: comments.slice(0, 5).map((c) => ({
|
||||
"@type": "Review",
|
||||
author: { "@type": "Person", name: c.author?.real_name || "بیمار" },
|
||||
reviewBody: c.comment,
|
||||
datePublished: new Date(c.created * 1000).toISOString(),
|
||||
})),
|
||||
}),
|
||||
...(doctor.social_media && {
|
||||
sameAs: Object.values(doctor.social_media).filter(Boolean),
|
||||
}),
|
||||
...(addresses.length > 0 && {
|
||||
workLocation: addresses.map((addr) => ({
|
||||
"@type": "MedicalClinic",
|
||||
name: addr.clinic_name || addr.name || `مطب دکتر ${doctor.name}`,
|
||||
address: {
|
||||
"@type": "PostalAddress",
|
||||
streetAddress: addr.address,
|
||||
},
|
||||
...(addr.telephone && { telephone: addr.telephone }),
|
||||
...(addr.map?.latitude && addr.map?.longitude && {
|
||||
geo: {
|
||||
"@type": "GeoCoordinates",
|
||||
latitude: addr.map.latitude,
|
||||
longitude: addr.map.longitude,
|
||||
},
|
||||
}),
|
||||
})),
|
||||
}),
|
||||
}
|
||||
: null;
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -37,7 +37,7 @@ export default function robots() {
|
||||
rules: {
|
||||
userAgent: '*',
|
||||
allow: '/',
|
||||
disallow: '/dashboard',
|
||||
disallow: ['/dashboard', '/panel'],
|
||||
},
|
||||
sitemap: `${baseUrl}/sitemap.xml`,
|
||||
};
|
||||
|
||||
+1
-91
@@ -1,12 +1,6 @@
|
||||
import { headers } from 'next/headers';
|
||||
import { getBaseUrl } from '../utils/sitemap';
|
||||
|
||||
function toSafeDate(value) {
|
||||
if (!value) return new Date();
|
||||
const d = new Date(value);
|
||||
return isNaN(d.getTime()) ? new Date() : d;
|
||||
}
|
||||
|
||||
const MAIN_DOMAIN = 'nobat724.com';
|
||||
|
||||
function getCurrentDomain() {
|
||||
@@ -33,95 +27,11 @@ function getStaticPages(baseUrl) {
|
||||
];
|
||||
}
|
||||
|
||||
async function getDoctorUrls(baseUrl) {
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
if (!API_URL) return [];
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/v1/doctors?page=1&limit=500`, {
|
||||
next: { revalidate: 3600 },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const data = await res.json();
|
||||
const doctors = data?.data || data?.doctors || data || [];
|
||||
return doctors
|
||||
.filter((d) => d?.uuid)
|
||||
.map((d) => ({
|
||||
url: `${baseUrl}/doctor/${d.uuid}`,
|
||||
lastModified: NOW,
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.8,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function getClinicUrls(baseUrl) {
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
if (!API_URL) return [];
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/v1/clinics?page=1&limit=500`, {
|
||||
next: { revalidate: 3600 },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const data = await res.json();
|
||||
const clinics = data?.data || data?.clinics || data || [];
|
||||
return clinics
|
||||
.filter((c) => c?.uuid)
|
||||
.map((c) => ({
|
||||
url: `${baseUrl}/clinic/${c.uuid}`,
|
||||
lastModified: NOW,
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.7,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function getBlogUrls(baseUrl) {
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
if (!API_URL) return [];
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/v1/blogs?page=1&limit=200`, {
|
||||
next: { revalidate: 3600 },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const data = await res.json();
|
||||
const blogs = data?.blogs || data?.data || data || [];
|
||||
return blogs
|
||||
.filter((b) => b?.slug || b?.uuid)
|
||||
.map((b) => ({
|
||||
url: `${baseUrl}/blog/${b.slug || b.uuid}`,
|
||||
lastModified: toSafeDate(b.created),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.6,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export default async function sitemap() {
|
||||
try {
|
||||
const domain = getCurrentDomain();
|
||||
const baseUrl = getBaseUrl(domain);
|
||||
|
||||
const [staticPages, doctorUrls, clinicUrls, blogUrls] = await Promise.all([
|
||||
Promise.resolve(getStaticPages(baseUrl)),
|
||||
getDoctorUrls(baseUrl),
|
||||
getClinicUrls(baseUrl),
|
||||
getBlogUrls(baseUrl),
|
||||
]);
|
||||
|
||||
const allUrls = [...staticPages, ...doctorUrls, ...clinicUrls, ...blogUrls];
|
||||
|
||||
return allUrls.filter(
|
||||
(item, index, arr) => arr.findIndex((i) => i.url === item.url) === index
|
||||
);
|
||||
return getStaticPages(baseUrl);
|
||||
} catch (error) {
|
||||
console.error('Error generating sitemap:', error);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user