|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import fs from 'fs'; |
| 4 | +import path from 'path'; |
| 5 | +import { fileURLToPath } from 'url'; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = path.dirname(__filename); |
| 9 | + |
| 10 | +const baseUrl = 'https://up-skill.app'; |
| 11 | +const currentDate = new Date().toISOString().split('T')[0]; |
| 12 | + |
| 13 | +const staticRoutes = [ |
| 14 | + { path: '/', priority: '1.0', changefreq: 'weekly' }, |
| 15 | + { path: '/about', priority: '0.8', changefreq: 'monthly' }, |
| 16 | + { path: '/faq', priority: '0.7', changefreq: 'monthly' }, |
| 17 | + { path: '/contact', priority: '0.7', changefreq: 'monthly' }, |
| 18 | + { path: '/courses', priority: '0.9', changefreq: 'daily' }, |
| 19 | + { path: '/login', priority: '0.5', changefreq: 'yearly' }, |
| 20 | + { path: '/register', priority: '0.5', changefreq: 'yearly' }, |
| 21 | +]; |
| 22 | + |
| 23 | +const generateSitemap = () => { |
| 24 | + const urls = staticRoutes.map(route => ` |
| 25 | + <url> |
| 26 | + <loc>${baseUrl}${route.path}</loc> |
| 27 | + <lastmod>${currentDate}</lastmod> |
| 28 | + <changefreq>${route.changefreq}</changefreq> |
| 29 | + <priority>${route.priority}</priority> |
| 30 | + </url>`).join(''); |
| 31 | + |
| 32 | + const sitemap = `<?xml version="1.0" encoding="UTF-8"?> |
| 33 | +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" |
| 34 | + xmlns:xhtml="http://www.w3.org/1999/xhtml"> |
| 35 | +${urls} |
| 36 | +</urlset>`; |
| 37 | + |
| 38 | + const sitemapPath = path.join(__dirname, '../public/sitemap.xml'); |
| 39 | + fs.writeFileSync(sitemapPath, sitemap.trim()); |
| 40 | + console.log('✓ Sitemap generated successfully at public/sitemap.xml'); |
| 41 | +}; |
| 42 | + |
| 43 | +generateSitemap(); |
0 commit comments