-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-sitemap.js
56 lines (46 loc) · 2.19 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { SitemapStream, streamToPromise } from 'sitemap';
import { createWriteStream } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Convert import.meta.url to __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const BASE_URL = 'https://www.yenreach.com'; // Replace with your site's URL
// List your site routes here
const urls = [
{ url: '/', changefreq: 'daily', priority: 1.0 },
{ url: '/explore', changefreq: 'daily', priority: 0.8 },
{ url: '/explore/products', changefreq: 'daily', priority: 0.8 },
{ url: '/explore/jobs', changefreq: 'daily', priority: 0.8 },
{ url: '/about', changefreq: 'monthly', priority: 0.7 },
{ url: '/blogs', changefreq: 'daily', priority: 0.7 },
{ url: '/faqs', changefreq: 'monthly', priority: 0.7 },
{ url: '/signup', changefreq: 'monthly', priority: 0.5 },
{ url: '/login', changefreq: 'monthly', priority: 0.5 },
{ url: '/terms', changefreq: 'monthly', priority: 0.5 },
{ url: '/privacy', changefreq: 'monthly', priority: 0.5 },
{ url: '/subsidiaries', changefreq: 'monthly', priority: 0.5 },
{ url: '/password-recovery', changefreq: 'monthly', priority: 0.5 },
{ url: '/password_reset', changefreq: 'monthly', priority: 0.5 },
{ url: '/contact', changefreq: 'monthly', priority: 0.5 },
{ url: '/users/profile', changefreq: 'monthly', priority: 0.7 },
{ url: '/users/profile/edit', changefreq: 'monthly', priority: 0.6 },
{ url: '/users/verify_payment', changefreq: 'monthly', priority: 0.6 },
{ url: '/users/billboard', changefreq: 'monthly', priority: 0.6 },
{ url: '/users/', changefreq: 'monthly', priority: 0.6 },
];
async function generateSitemap() {
const sitemap = new SitemapStream({ hostname: BASE_URL });
const writeStream = createWriteStream(path.resolve(__dirname, 'dist', 'sitemap.xml'));
urls.forEach(url => {
sitemap.write(url);
});
sitemap.end();
const sitemapOutput = await streamToPromise(sitemap).then((data) => data.toString());
writeStream.write(sitemapOutput);
writeStream.end();
console.log('Sitemap generated successfully!');
}
generateSitemap().catch(err => {
console.error(err);
});