-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-sitemap.js
30 lines (25 loc) · 1.08 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
import { SitemapStream, streamToPromise } from 'sitemap';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const sitemapStream = new SitemapStream({ hostname: 'https://rcstudio.tw' });
const urls = [
{ url: '/', lastmod: new Date().toISOString() },
{ url: '/About', lastmod: new Date().toISOString() },
{ url: '/Case', lastmod: new Date().toISOString() },
{ url: '/JoinUS', lastmod: new Date().toISOString() },
{ url: '/contactUS', lastmod: new Date().toISOString() },
{ url: '/No', lastmod: new Date().toISOString() },
{ url: '/news', lastmod: new Date().toISOString() },
];
urls.forEach(url => sitemapStream.write(url));
sitemapStream.end();
streamToPromise(sitemapStream).then(data => {
const outputPath = path.resolve(__dirname, 'public', 'sitemap.xml');
fs.writeFileSync(outputPath, data.toString());
console.log('Sitemap generated at:', outputPath);
}).catch(error => {
console.error('Error generating sitemap:', error);
});