-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitemap-update.js
31 lines (24 loc) · 901 Bytes
/
sitemap-update.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
const xml2js = require("xml2js");
const util = require('util');
xml2js.Parser.prototype.parseStringPromise = util.promisify(xml2js.parseString);
const getUrlsFromSitemap_HT = async (SitemapUrl_HT) => {
response = await fetch(SitemapUrl_HT, {
method: "get",
headers: {
"Content-Type" : "application/json"
}
});
SitemapXML = await response.text();
var parser = new xml2js.Parser();
SitemapObject = await parser.parseStringPromise(SitemapXML);
const urlObjects = SitemapObject.urlset.url.map((urlObjectNonstandard) => {
urlObject = {}
urlObject.pageUrl = urlObjectNonstandard.loc[0];
// Assumes Hindustan Times sitemap date/time follows ISO 8601 format
urlObject.lastModified = Date.parse(urlObjectNonstandard.lastmod[0]);
urlObject.changeFreq = urlObjectNonstandard.changefreq[0];
return urlObject;
})
return urlObjects;
}
module.exports = { getUrlsFromSitemap_HT };