-
Notifications
You must be signed in to change notification settings - Fork 4
/
generateSitemap.js
61 lines (51 loc) · 1.96 KB
/
generateSitemap.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
let fs = require('fs')
let zlib = require('zlib')
let sm = require('sitemap')
let axios = require('axios')
let slugify = require('slugify')
console.log('Generating sitemap...')
// Add root
let urls = [
{ url: '/', changefreq: 'weekly', priority: 0.6 },
{ url: '/about/', changefreq: 'weekly', priority: 1.0 },
{ url: '/trading/station/ranking', changefreq: 'hourly', priority: 0.8 }
]
// Add market-types
axios.get('https://crest-tq.eveonline.com/market/types/').then(
function (response) {
const pageCount = response.data.pageCount
let promises = []
for (let page = 1; page <= pageCount; page++) {
promises.push(axios.get('https://crest-tq.eveonline.com/market/types/?page=' + page))
}
return axios.all(promises)
}).then(function (results) {
let types = [].concat.apply([], results.map(function (response) { return response.data.items }))
types.forEach(function (type) {
const slug = (slugify(type.type.name) + '-' + String(type.type.id)).replace(/'/g, '')
urls.push({ url: '/market/' + slug + '/', changefreq: 'hourly' })
urls.push({ url: '/market/' + slug + '/regions/', changefreq: 'hourly' })
urls.push({ url: '/market/' + slug + '/bid/', changefreq: 'hourly' })
urls.push({ url: '/market/' + slug + '/ask/', changefreq: 'hourly' })
})
return true
}).then(function (_ignoredResult) {
// Creates a sitemap object given the input configuration with URLs
let sitemap = sm.createSitemap({
hostname: 'https://element-43.com',
urls: urls
})
// Generates XML with a callback function
sitemap.toXML(function (err, xml) { if (err) { console.error(err) } })
// Dump XML to file
let xml = sitemap.toString()
let outputStream = fs.createWriteStream('./static/sitemap.xml.gz')
let compressor = zlib.createGzip()
compressor.pipe(outputStream)
compressor.write(xml)
compressor.end()
console.log('Done!')
}).catch(function (error) {
console.error(error)
console.error('Something went wrong with CREST!')
})