-
Notifications
You must be signed in to change notification settings - Fork 13
/
gen-sitemap.js
46 lines (33 loc) · 1.37 KB
/
gen-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
const fs = require('fs');
const recursive = require('recursive-readdir');
const { SitemapStream, streamToPromise } = require( 'sitemap' )
const { Readable } = require( 'stream' )
const links = [];
const workerFarm = require('worker-farm');
const workers = workerFarm(require.resolve('./worker'));
let ret = 0;
recursive(process.argv[2], ['.*', '!*.md','README.md'], (err, files) => {
for (const file of files) {
workers(file, (err, nativeData) => {
if (err) {
console.log(err);
process.exit(0);
return;
}
const mtime = fs.statSync(file).mtime;
const native = nativeData.result;
links.push({
url: 'https://docs.fivem.net/natives/?_' + native.hash,
lastmod: mtime.toISOString()
});
process.stderr.write(`\r${ret}/${files.length} - ${native.name || native.hash} `)
++ret;
if (ret >= files.length) {
process.stderr.write('\nDone!');
const stream = new SitemapStream( { hostname: 'https://docs.fivem.net/natives/' } );
streamToPromise(Readable.from(links).pipe(stream)).then((data) => data.toString()).then((str) => console.log(str));
workerFarm.end(workers);
}
});
}
});