-
Notifications
You must be signed in to change notification settings - Fork 1
/
route-generator.js
91 lines (86 loc) · 2.25 KB
/
route-generator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const fetch = require('node-fetch');
const fs = require('fs');
const builder = require('xmlbuilder');
const siteTitle = 'DevFest 2022 Kuala Lumpur';
let prerenderJson = [
{
url: '/',
title: siteTitle
},
{
url: '/attending',
title: 'Attending - ' + siteTitle
},
{
url: '/registration',
title: 'Registration - ' + siteTitle
},
{
url: '/faq',
title: 'FAQ - ' + siteTitle
},
// {
// url: '/faq/communityguidelines',
// title: 'Community Guidelines - DevFest 2022 Kuala Lumpur'
// },
{
url: '/speakers',
title: 'Speakers - ' + siteTitle
},
{
url: '/schedule',
title: 'Schedule - ' + siteTitle
},
{
url: '/sponsor',
title: 'Sponsor - ' + siteTitle
},
];
const base = 'https://devfest.gdgkl.dev';
const getSpeakers = new Promise((resolve) => {
// fetch(`${dbUrl}/speakers.json`)
// .then((response) => {
// response.json().then((data) => {
// let speakers = [];
// speakers = Object.keys(data).map(item => ({
// url: `/speakers/${item}`,
// title: `${data[item].name} - Speakers - DevFest 2022 Kuala Lumpur`
// }));
// resolve(speakers);
// });
// });
resolve([]);
});
const getSessions = new Promise((resolve) => {
// fetch(`${dbUrl}/sessions.json`)
// .then((response) => {
// response.json().then((data) => {
// let sessions = [];
// sessions = Object.keys(data).map(item => ({
// url: `/schedule/${item}`,
// title: `${data[item].title} - Schedule - DevFest 2022 Kuala Lumpur`
// }));
// resolve(sessions);
// });
// });
resolve([]);
});
Promise.all([getSpeakers, getSessions]).then((values) => {
const data = [...prerenderJson, ...values[0], ...values[1]];
fs.writeFile('src/prerender-urls.json', JSON.stringify(data, null, 4), () => { });
const lastMod = new Date().toISOString();
let xml = builder.create('urlset', { version: '1.0', encoding: 'UTF-8' });
data.forEach(item => {
xml.ele('url')
.ele('loc')
.txt(`${base}${item.url}`)
.up()
.ele('lastmod')
.text(lastMod)
.up();
});
xml.end({ pretty: true });
fs.writeFile('src/sitemap.xml', xml.doc().toString({ pretty: true }), () => { });
// eslint-disable-next-line no-console
console.log('\x1b[32m%s\x1b[0m', `Pre-render config generated successfully: ${data.length} routes generated.`);
});