-
Notifications
You must be signed in to change notification settings - Fork 1
/
sitemap.js
41 lines (33 loc) · 1009 Bytes
/
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
import * as fs from 'fs';
import { create } from 'xmlbuilder2';
import moment from 'moment';
const pages = ['/', '/community', '/cardEdit', '/mypage'];
const addPath = (root, path, freq) => {
root
.ele('url')
.ele('loc')
.txt(path)
.up()
.ele('lastmod')
.txt(moment().format('YYYY-MM-DD'))
.up()
.ele('changefreq')
.txt(freq ? freq : 'yearly')
.up()
.up();
};
const generateSitemapXml = () => {
const root = create({ version: '1.0', encoding: 'UTF-8' }).ele('urlset', {
xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9',
});
const BASE = 'https://my-pokehub.vercel.app';
addPath(root, BASE + pages[0], 'weekly');
pages.slice(1).forEach((page) => {
addPath(root, BASE + page);
});
return root.end({ prettyPrint: true });
};
const sitemapXml = generateSitemapXml();
const filename = './src/app/sitemap.xml';
fs.writeFileSync(filename, sitemapXml);
console.log('사이트맵 생성 완료');