fix: enhance domain handling in sitemap generation and add XML escaping utility
This commit is contained in:
+15
-3
@@ -13,9 +13,15 @@ import {
|
||||
|
||||
// Get current domain from headers
|
||||
function getCurrentDomain() {
|
||||
const headersList = headers();
|
||||
const host = headersList.get('host');
|
||||
return host || DOMAIN_CONFIG.MAIN_DOMAIN;
|
||||
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
|
||||
@@ -225,12 +231,17 @@ 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}`);
|
||||
|
||||
// Get all URLs
|
||||
const staticPages = getStaticPages(baseUrl);
|
||||
const doctorSearchUrls = getDoctorSearchUrls(domain, baseUrl);
|
||||
const clinicSearchUrls = getClinicSearchUrls(domain, baseUrl);
|
||||
const specialtyUrls = getSpecialtyUrls(domain, baseUrl);
|
||||
|
||||
console.log(`Generated URLs - Static: ${staticPages.length}, Doctors: ${doctorSearchUrls.length}, Clinics: ${clinicSearchUrls.length}, Specialties: ${specialtyUrls.length}`);
|
||||
|
||||
// Combine all URLs
|
||||
const allUrls = [
|
||||
...staticPages,
|
||||
@@ -244,6 +255,7 @@ export default async function sitemap() {
|
||||
arr.findIndex(i => i.url === item.url) === index
|
||||
);
|
||||
|
||||
console.log(`Total unique URLs: ${uniqueUrls.length}`);
|
||||
return uniqueUrls;
|
||||
} catch (error) {
|
||||
console.error('Error generating sitemap:', error);
|
||||
|
||||
Reference in New Issue
Block a user