-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgenerate-sitemap.js
45 lines (33 loc) · 1.18 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
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const utils = require('../js/utils/utils-node');
const SITEMAP_FILE = './sitemap.txt';
const CONFERENCES_GLOB_PATTERN = './data/conferences/*/*.yaml';
const BASE_URL = 'https://confpad.io/';
const buildUrl = (conferenceId, talkIndex, talk) => {
if (talkIndex && talk) {
return `${BASE_URL}${conferenceId}/${talkIndex}-${utils.slugifyTitle(talk.title)}`;
}
return `${BASE_URL}${conferenceId}`;
};
let conferenceFiles = glob.sync(CONFERENCES_GLOB_PATTERN);
// Build sitemap
let stream = fs.createWriteStream(SITEMAP_FILE);
stream.once('open', () => {
conferenceFiles.forEach(conferenceFile => {
let conferenceId = path.parse(conferenceFile).name;
let conference = utils.getJSON(conferenceFile);
if (conference.conference.status === utils.INFO_STATUS_INCOMPLETE) {
return;
}
// Conference root
stream.write(`${buildUrl(conferenceId)}\n`);
// Conference talks
conference.talks.forEach((talk, index) => {
stream.write(`${buildUrl(conferenceId, index + 1, talk)}\n`);
});
});
stream.end();
});
console.log(`Sitemap generated at: ${SITEMAP_FILE}`);