forked from codervivek5/VigyBag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-sitemap.js
36 lines (29 loc) · 1.21 KB
/
generate-sitemap.js
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
import { SitemapStream, streamToPromise } from 'sitemap';
import { createWriteStream } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
// Get the current directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const links = [
{ url: '/', changefreq: 'daily', priority: 1.0 },
{ url: '/about', changefreq: 'weekly', priority: 0.8 },
{ url: '/products/', changefreq: 'daily', priority: 0.9 },
{ url: '/categories/', changefreq: 'daily', priority: 0.9 },
{ url: '/blog/', changefreq: 'daily', priority: 0.9 },
{ url: '/help/', changefreq: 'daily', priority: 0.9 },
{ url: '/login/', changefreq: 'daily', priority: 0.9 },
{ url: '/signup/', changefreq: 'daily', priority: 0.9 },
// Add other site routes here as needed
];
const generateSitemap = async () => {
const sitemap = new SitemapStream({ hostname: 'https://www.vigybag.com' });
const writeStream = createWriteStream(path.resolve(__dirname, 'public', 'sitemap.xml'));
sitemap.pipe(writeStream);
links.forEach(link => sitemap.write(link));
sitemap.end();
await streamToPromise(sitemap);
console.log('Sitemap generated!');
};
generateSitemap();