seo check
This commit is contained in:
+83
-88
@@ -1,7 +1,6 @@
|
||||
import { headers } from 'next/headers';
|
||||
import cityData from '../data/city.json';
|
||||
import specialtyData from '../data/specialties.json';
|
||||
import stateData from '../data/state.json';
|
||||
import {
|
||||
DOMAIN_CONFIG,
|
||||
isMainDomain,
|
||||
@@ -11,93 +10,103 @@ import {
|
||||
getBaseUrl
|
||||
} from '../utils/sitemap';
|
||||
|
||||
// Get current domain from headers
|
||||
function getCurrentDomain() {
|
||||
try {
|
||||
const headersList = headers();
|
||||
const host = headersList.get('host');
|
||||
return host || DOMAIN_CONFIG.MAIN_DOMAIN;
|
||||
} catch (error) {
|
||||
// Fallback for static generation
|
||||
console.warn('Headers not available during static generation, using main domain');
|
||||
return DOMAIN_CONFIG.MAIN_DOMAIN;
|
||||
}
|
||||
}
|
||||
|
||||
// Get city data based on domain
|
||||
function getCityByDomain(domain) {
|
||||
return cityData.find(city => city.domain === domain);
|
||||
}
|
||||
|
||||
// Get state name by province_id
|
||||
function getStateById(provinceId) {
|
||||
return stateData.find(state => state.id === provinceId)?.name || '';
|
||||
}
|
||||
|
||||
// Generate static pages URLs
|
||||
function getStaticPages(baseUrl) {
|
||||
return [
|
||||
{
|
||||
url: baseUrl,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily',
|
||||
priority: 1,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/about-us`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/contact-us`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/blogs`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.9,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/doctors`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.9,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/clinics`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.9,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/specialties`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.9,
|
||||
},
|
||||
{ url: baseUrl, lastModified: new Date(), changeFrequency: 'daily', priority: 1 },
|
||||
{ url: `${baseUrl}/about-us`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.8 },
|
||||
{ url: `${baseUrl}/contact-us`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.8 },
|
||||
{ url: `${baseUrl}/blogs`, lastModified: new Date(), changeFrequency: 'weekly', priority: 0.9 },
|
||||
{ url: `${baseUrl}/doctors`, lastModified: new Date(), changeFrequency: 'daily', priority: 0.9 },
|
||||
{ url: `${baseUrl}/clinics`, lastModified: new Date(), changeFrequency: 'daily', priority: 0.9 },
|
||||
{ url: `${baseUrl}/specialties`, lastModified: new Date(), changeFrequency: 'weekly', priority: 0.9 },
|
||||
];
|
||||
}
|
||||
|
||||
// Generate doctor search URLs based on domain
|
||||
function getDoctorSearchUrls(domain, baseUrl) {
|
||||
// Return empty array - no URLs with search parameters
|
||||
return [];
|
||||
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: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.8,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Generate clinic search URLs
|
||||
function getClinicSearchUrls(domain, baseUrl) {
|
||||
// Return empty array - no URLs with search parameters
|
||||
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: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.7,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Generate specialty pages URLs
|
||||
function getSpecialtyUrls(domain, baseUrl) {
|
||||
// Return empty array - no specialty URLs
|
||||
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: b.created ? new Date(b.created) : new Date(),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.6,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export default async function sitemap() {
|
||||
@@ -105,34 +114,20 @@ export default async function sitemap() {
|
||||
const domain = getCurrentDomain();
|
||||
const baseUrl = getBaseUrl(domain);
|
||||
|
||||
console.log(`Generating sitemap for domain: ${domain}, baseUrl: ${baseUrl}`);
|
||||
console.log(`City data length: ${cityData.length}, Specialty data length: ${specialtyData.length}`);
|
||||
const [staticPages, doctorUrls, clinicUrls, blogUrls] = await Promise.all([
|
||||
Promise.resolve(getStaticPages(baseUrl)),
|
||||
getDoctorUrls(baseUrl),
|
||||
getClinicUrls(baseUrl),
|
||||
getBlogUrls(baseUrl),
|
||||
]);
|
||||
|
||||
// Get all URLs
|
||||
const staticPages = getStaticPages(baseUrl);
|
||||
const doctorSearchUrls = getDoctorSearchUrls(domain, baseUrl);
|
||||
const clinicSearchUrls = getClinicSearchUrls(domain, baseUrl);
|
||||
const specialtyUrls = getSpecialtyUrls(domain, baseUrl);
|
||||
const allUrls = [...staticPages, ...doctorUrls, ...clinicUrls, ...blogUrls];
|
||||
|
||||
console.log(`Generated URLs - Static: ${staticPages.length}, Doctors: ${doctorSearchUrls.length}, Clinics: ${clinicSearchUrls.length}, Specialties: ${specialtyUrls.length}`);
|
||||
|
||||
// Combine all URLs
|
||||
const allUrls = [
|
||||
...staticPages,
|
||||
...doctorSearchUrls,
|
||||
...clinicSearchUrls,
|
||||
...specialtyUrls,
|
||||
];
|
||||
|
||||
// Remove duplicates based on URL
|
||||
const uniqueUrls = allUrls.filter((item, index, arr) =>
|
||||
arr.findIndex(i => i.url === item.url) === index
|
||||
return allUrls.filter(
|
||||
(item, index, arr) => arr.findIndex((i) => i.url === item.url) === index
|
||||
);
|
||||
|
||||
|
||||
return uniqueUrls;
|
||||
} catch (error) {
|
||||
console.error('Error generating sitemap:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user