const fs = require('fs'); const { SitemapStream, streamToPromise } = require('sitemap'); const path = require('path'); const hostname = 'https://metatroncube.in'; const addTrailingSlash = true; // ✅ Set this true if your Next.js uses trailingSlash: true // // 🔧 Utility to format URLs based on config // const formatUrl = (url) => { // if (addTrailingSlash && !url.endsWith('/')) return url + '/'; // if (!addTrailingSlash && url.endsWith('/') && url !== '/') return url.slice(0, -1); // return url; // }; // Add a trailing slash only for “directory-like” URLs const shouldAddSlash = (url) => { // keep "/" as is if (url === '/') return false; // don't touch file-like URLs (has extension) if (/\.[a-z0-9]{2,6}(\?.*)?$/i.test(url)) return false; return true; }; const formatUrl = (url) => { // normalize to leading slash if (!url.startsWith('/')) url = '/' + url; if (addTrailingSlash && shouldAddSlash(url) && !url.endsWith('/')) { return url + '/'; } if (!addTrailingSlash && url.endsWith('/') && url !== '/') { return url.slice(0, -1); } return url; }; // ✅ Static pages const staticLinks = [ { url: '/', changefreq: 'daily', priority: 1.0 }, { url: '/services-digital-solutions/', changefreq: 'daily', priority: 0.7 }, { url: '/about/', changefreq: 'weekly', priority: 0.7 }, { url: '/careers/', changefreq: 'weekly', priority: 0.7 }, { url: '/portfolio/', changefreq: 'weekly', priority: 0.7 }, { url: '/blog/', changefreq: 'weekly', priority: 0.7 }, { url: '/contact/', changefreq: 'monthly', priority: 0.5 }, { url: '/faq/', changefreq: 'monthly', priority: 0.5 }, { url: '/accessibility-statement-for-metatroncube-software-solutions/', changefreq: 'weekly', priority: 0.6 }, { url: '/privacy-policy/', changefreq: 'weekly', priority: 0.6 }, { url: '/service/website-development-company/', changefreq: 'weekly', priority: 0.6 }, { url: '/service/mobile-application-development/', changefreq: 'weekly', priority: 0.6 }, { url: '/service/graphic-designing-company/', changefreq: 'weekly', priority: 0.6 }, { url: '/service/ui-ux-designing/', changefreq: 'weekly', priority: 0.6 }, { url: '/service/search-engine-optimization-seo-content-writing/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/digital-solutions/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/app-development-waterloo/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/kitchener-waterloo-website-design-services/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/professional-website-designers-in-waterloo/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/waterloo-seo-services/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/web-design-toronto-custom-website-creation-by-metatroncube-software-solutions/', changefreq: 'weekly', priority: 0.6 }, // { url: '/service/web-page-design-in-waterloo/', changefreq: 'weekly', priority: 0.6 }, ]; // ✅ Dynamic blog posts const blogPosts = [ { slug: 'top-web-development-trends-to-watch-in-2025/' }, { slug: 'why-every-startup-needs-a-mobile-app-in-2025/' }, { slug: 'how-seo-content-writing-boost-online-sales/' }, { slug: 'top-digital-marketing-strategies-for-2025-that-actually-work/' }, { slug: 'why-ui-ux-design-can-make-or-break-your-app-in-2025/' }, { slug: 'how-metatroncube-transforms-businesses-through-digital-marketing-excellence/' }, { slug: 'effective-on-page-seo-tips-for-small-businesses-in-2025/' }, { slug: 'how-does-metatroncube-approach-mobile-app-development-from-idea-to-launch/' }, { slug: 'what-digital-marketing-services-does-metatroncube-offer/' }, { slug: 'does-metatroncube-handle-web-hosting-and-maintenance/' }, { slug: 'advanced-tools-technologies-metatroncube-growth-strategy-waterloo/' }, { slug: 'ui-ux-design-services-metatroncube/' }, { slug: 'how-metatroncube-a-digital-marketing-agency-in-india-helped-clients-increase-their-leads/' }, { slug: 'metatroncube-india-the-digital-marketing-agency-in-india-driving-real-business-growth/' }, { slug: 'does-metatroncube-provide-website-development-and-seo-together-for-indian-businesses' }, { slug: 'does-metatroncube-really-work-on-technical-seo-and-on-page-optimization-in-india' }, { slug: 'metatroncube-india-the-best-marketing-agency-for-transforming-your-brand' }, { slug: 'does-metatroncube-work-on-technical-seo-and-on-page-optimization' }, { slug: 'what-seo-strategies-does-metatroncube-use-to-drive-organic-traffic-in-india' }, { slug: 'how-metatroncube-improves-core-web-vitals-to-boost-google-rankings-in-india' }, { slug: 'can-metatroncube-really-improve-your-websites-conversion-rates-in-india' }, { slug: 'does-metatroncube-really-offer-data-driven-digital-marketing-services-in-india' }, { slug: 'does-metatroncube-have-experience-in-the-food-beverage-health-tech-or-other-verticals' }, { slug: 'does-metatroncube-work-on-technical-seo-and-on-page-optimization' }, { slug: 'how-metatroncube-improves-core-web-vitals-to-boost-google-rankings-for-etobicoke-businesses' }, { slug: 'premium-marketing-strategies-with-metatroncube-india-for-chennai' }, { slug: 'best-mobile-app-development-service-in-india-for-scalable-business-growth' }, { slug: 'best-website-development-service-in-india-for-high-impact-online-presence' }, { slug: 'best-digital-marketing-service-in-india-for-business-growth-and-online-visibility' }, { slug: 'best-seo-service-in-india-to-improve-google-rankings-and-organic-traffic' }, { slug: 'how-metatroncube-turns-business-websites-into-high-converting-lead-machines' }, { slug: 'top-marketing-agency-in-india-metatroncube-india-helps-brands-grow' }, { slug: 'seo-mistakes-that-are-holding-business-websites-back-in-2026' }, { slug: 'digital-marketing-trends-indian-businesses-must-prepare-for-in-2026' }, { slug: 'how-local-seo-helps-businesses-rank-higher-and-attract-nearby-customers' }, { slug: 'metatroncube-india-creative-results-driven-marketing-experts' }, { slug: 'graphic-designing-company-why-design-matters' }, { slug: 'ui-ux-designing-creating-interfaces-people-love' }, ]; // Convert blog slugs to sitemap entries const blogLinks = blogPosts.map(post => ({ url: `/${post.slug}`, changefreq: 'weekly', priority: 0.6, })); const seen = new Set(); const allLinks = [...staticLinks, ...blogLinks] .map(link => ({ ...link, url: formatUrl(link.url) })) .filter(link => { if (seen.has(link.url)) return false; seen.add(link.url); return true; }); async function generateSitemap() { try { const sitemap = new SitemapStream({ hostname }); const filePath = path.resolve(__dirname, '../public/sitemap.xml'); const writeStream = fs.createWriteStream(filePath); sitemap.pipe(writeStream); console.log('📦 Writing URLs to sitemap:'); allLinks.forEach(link => { console.log(' -', hostname + link.url); sitemap.write(link); }); sitemap.end(); await Promise.all([ streamToPromise(sitemap), new Promise(resolve => writeStream.on('finish', resolve)), ]); console.log(`✅ Sitemap.xml created successfully! at: ${filePath}`); } catch (error) { console.error('❌ Error creating sitemap.xml:', error); } } generateSitemap();