-
Notifications
You must be signed in to change notification settings - Fork 2
/
sitemap_generation.js
48 lines (40 loc) · 1.08 KB
/
sitemap_generation.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
"use strict";
const yaml = require("js-yaml");
const fs = require("fs");
const sm = require("sitemap");
const hostname = "https://@hub_fqdn@";
const pathPrefix = "/#/documentation/";
let appendUrl = function (obj, stack, cb) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (typeof obj[property] === "object") {
appendUrl(obj[property], stack + "." + property, cb);
} else {
cb(obj[property]);
}
}
}
};
try {
let args = process
.argv
.slice(2);
const index = yaml.safeLoad(fs.readFileSync("index.yml", "utf8"));
let sitemap = sm.createSitemap({
hostname: (args.length && args[0])
? args[0]
: hostname
});
appendUrl(index, "", (value) => {
sitemap.add({
url: value.replace(/(ref:)?(.*).md/g, pathPrefix + "$2")
});
});
sitemap.toXML(function (err, xml) {
if (!err) {
fs.writeFileSync("sitemap.xml", xml);
}
});
} catch (e) {
console.log(e);
}