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