-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_sitemap.js
41 lines (35 loc) · 1.43 KB
/
build_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 fs from "fs";
const site = 'https://dimitar5555.github.io/sofiatraffic-schedules/';
const url_prefix = '#!';
function read_file(file) {
return JSON.parse(fs.readFileSync(`docs/data/${file}.json`).toString());
}
function init(){
let routes = read_file('routes');
let trips = read_file('trips');
let directions = read_file('directions');
let stops = read_file('stops');
run(routes, trips, directions, stops);
}
function generate_url_entry(hash, priority, sitemap) {
sitemap.push('<url>');
sitemap.push(`<loc>${site}${url_prefix}${hash}/</loc>`);
sitemap.push('<changefreq>weekly</changefreq>');
sitemap.push(`<priority>${priority}</priority>`);
sitemap.push('</url>');
}
function run(routes, trips, directions, stops){
var sitemap = ['<?xml version="1.0" encoding="UTF-8"?>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'];
for(const page of ['schedules', 'stops_map']) {
generate_url_entry(`${page}`, 1, sitemap);
}
routes.forEach(route => {
generate_url_entry(`${route.type}/${route.route_ref}`, 0.7, sitemap);
});
stops.forEach(stop => {
generate_url_entry(`stop/${stop.code}`, 0.5, sitemap);
})
sitemap.push('</urlset>');
fs.writeFileSync('docs/sitemap.xml', sitemap.join('\n'));
}
init();