Files
nobat724_front/app/blog/sitemap.js
T
hamed a8c3a57114 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
2026-06-21 12:35:15 +03:30

50 lines
1.5 KiB
JavaScript

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 [];
}
}