import fs from 'fs'; import path from 'path'; import { locationData, serviceData, blogPostData } from '../src/data/seoData'; const BASE_URL = process.env.BASE_URL || 'https://bayareait.services'; /** * Generates the sitemap.xml content */ const generateSitemap = () => { const currentDate = new Date().toISOString().split('T')[0]; let xml = ` `; // Static Pages const staticPages = [ '', '/services', '/blog', '/contact', '/about' ]; staticPages.forEach(page => { xml += ` ${BASE_URL}${page} ${currentDate} monthly ${page === '' ? '1.0' : '0.8'} `; }); // Location Pages locationData.forEach(page => { xml += ` ${BASE_URL}/${page.slug} ${currentDate} weekly 0.9 `; }); // Service Pages serviceData.forEach(page => { xml += ` ${BASE_URL}/${page.slug} ${currentDate} weekly 0.9 `; }); // Blog Posts blogPostData.forEach(post => { xml += ` ${BASE_URL}/blog/${post.slug} ${currentDate} monthly 0.7 `; }); xml += ``; return xml; }; // Write to public/sitemap.xml const sitemap = generateSitemap(); const outputPath = path.resolve(process.cwd(), 'public/sitemap.xml'); // Ensure public directory exists const publicDir = path.dirname(outputPath); if (!fs.existsSync(publicDir)) { fs.mkdirSync(publicDir, { recursive: true }); } fs.writeFileSync(outputPath, sitemap); console.log(`✅ Sitemap generated at ${outputPath}`);