const fs = require('fs'); const { SitemapStream, streamToPromise } = require('sitemap'); const path = require('path'); const hostname = 'https://metatroncubesolutions.com'; 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: '/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-marketing-agency-in-canada/', 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: '5-tips-to-create-viral-content-that-drives-engagement' }, { slug: 'instagram-vs-facebook-choosing-the-right-platform-for-your-business' }, { slug: 'how-local-seo-can-drive-more-foot-traffic-to-your-business' }, { slug: 'on-page-vs-off-page-seo-what-every-business-owner-needs-to-know' }, { slug: 'how-to-create-a-winning-digital-marketing-strategy-for-your-business' }, { slug: 'white-hat-vs-black-hat-seo-an-in-depth-link-building-guide' }, { slug: 'how-to-boost-your-small-business-with-effective-digital-marketing-strategies' }, { slug: 'the-importance-of-local-seo-for-real-estate-agents' }, { slug: 'how-to-optimize-your-website-for-voice-search' }, { slug: 'how-ai-is-revolutionizing-web-development-and-seo' }, { slug: 'top-digital-marketing-agency-in-canada-metatroncube-software-solutions' }, { slug: 'best-digital-marketing-company-in-canada-metatroncube-solutions' }, { slug: 'web-designers-for-small-business' }, { slug: 'mobile-commerce-2024-web-app-development-evolution' }, { slug: 'how-to-personalize-cold-emails-without-spending-hours-on-research' }, { slug: 'how-to-overcome-the-biggest-challenges-in-cold-emailing-b2b-success' }, { slug: '9-powerful-free-google-tools-to-grow-your-business' }, { slug: '5-digital-marketing-mistakes-every-small-business-must-avoid' }, { slug: 'how-digital-solutions-drove-success-for-a-local-business' }, { slug: 'ai-driven-seo-how-to-future-proof-your-search-strategy' }, { slug: 'mastering-omnichannel-marketing-strategies-for-2026' }, { slug: 'how-metatroncube-solutions-improve-local-seo-waterloo' }, { slug: 'why-metatroncube-solutions-top-choice-social-media-marketing-waterloo' }, { slug: 'how-does-metatroncube-solutions-help-businesses-get-more-local-customers-through-search-engines' }, { slug: 'can-metatroncube-solutions-optimize-my-google-business-profile' }, { slug: 'seo-services-waterloo-small-businesses-metatroncube' }, { slug: 'boost-google-maps-ranking-waterloo-metatroncube' }, { slug: 'how-metatroncube-solutions-uses-ai-tools-to-boost-your-marketing-in-toronto' }, { slug: 'what-types-of-social-media-ads-does-metatroncube-solutions-recommend-for-small-businesses-in-toronto' }, { slug: 'should-i-run-facebook-or-google-ads-for-my-business-and-can-metatroncube-solutions-manage-them' }, { slug: 'is-metatroncube-solutions-the-best-ppc-agency-in-waterloo' }, { slug: 'how-can-metatroncube-solutions-help-me-get-more-followers-for-my-local-business' }, { slug: 'how-to-track-roi-from-your-website-and-marketing-campaigns-with-metatroncube-solutions' }, { slug: 'does-metatroncube-solutions-provide-ai-powered-marketing-solutions-for-local-businesses-in-waterloo' }, { slug: 'how-can-i-track-roi-from-my-website-and-marketing-campaigns-with-metatroncube-solutions-in-waterloo' }, { slug: 'can-metatroncube-solutions-manage-my-social-media-campaigns-from-start-to-finish' }, { slug: 'does-metatroncube-solutions-provide-website-audits-for-small-businesses' }, { slug: 'can-metatroncube-solutions-handle-both-seo-and-ppc-campaigns-for-my-business-in-waterloo' }, { slug: 'what-types-of-social-media-ads-does-metatroncube-solutions-recommend-for-small-businesses-in-waterloo' }, { slug: 'driving-digital-growth-with-metatroncubes-performance-focused-marketing-strategies' }, { slug: 'how-metatroncube-helps-businesses-scale-faster-with-smart-digital-solutions' }, { slug: 'building-powerful-digital-brands-with-metatroncube-creative-technical-expertise' }, { slug: 'professional-digital-marketing-services-in-canada-for-sustainable-business-growth' }, { slug: 'custom-website-development-solutions-in-canada-for-modern-businesses' }, { slug: 'is-metatroncube-solutions-the-top-choice-for-social-media-marketing-in-waterloo' }, { slug: 'how-can-metatroncube-solutions-improve-mobile-ux-for-my-business-website' }, { slug: 'is-metatroncube-solutions-a-good-agency-for-website-redesign-in-waterloo' }, { slug: 'seo-for-small-businesses-waterloo' }, { slug: 'modern-business-website-features-waterloo' }, { slug: 'why-social-media-management-important-business' }, { slug: 'why-you-need-digital-marketing-agency-business-growth' }, { slug: 'how-much-does-it-cost-to-hire-a-small-business-digital-marketing-agency-in-toronto' }, { slug: 'digital-marketing-agency-pricing-models-explained' }, { slug: 'how-custom-software-development-helps-businesses-scale-faster' }, { slug: 'top-benefits-of-choosing-custom-software-over-off-the-shelf-solutions' }, ]; // Convert blog slugs to sitemap entries const blogLinks = blogPosts.map(post => ({ url: `/${post.slug}`, changefreq: 'weekly', priority: 0.6 })); const allLinks = [...staticLinks, ...blogLinks].map(link => ({ ...link, url: formatUrl(link.url), })); async function generateSitemap() { try { const sitemap = new SitemapStream({ hostname: hostname }); const writeStream = fs.createWriteStream(path.resolve(__dirname, '../public/sitemap.xml')); sitemap.pipe(writeStream); console.log('📦 Writing URLs to sitemap:'); allLinks.forEach(link => { console.log(' -', hostname + link.url); sitemap.write(link); }); sitemap.end(); await streamToPromise(sitemap); console.log('✅ sitemap.xml created successfully!'); } catch (error) { console.error('❌ Error creating sitemap.xml:', error); } } generateSitemap();