-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (48 loc) · 1.7 KB
/
index.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
var sm = require('sitemap')
, fs = require('fs')
, request= require('sync-request')
, zlib = require('zlib')
, htmlToText = require('html-to-text')
, url='https://api.shuvayatra.org/v1/api/posts'
, urls=[];
while (url!==null) {
let res=request('GET', url);
console.log('processing for '+url);
let posts=JSON.parse(res.body);
for (let post of posts.data) {
let postNode={
url:'https://shuvayatra.org/post/'+post.id,
};
let videos=[];
let images=[];
if(post.type==='video' && post.data.thumbnail!=='' && post.title!=='' && post.description!==''){
let video={
"thumbnail_loc":post.data.thumbnail,
"title":post.title,
"description":htmlToText.fromString(post.description)
};
videos.push(video);
} else if (post.featured_image!==''){
images.push({
url: post.featured_image
});
}
postNode.img=images;
postNode.video=videos;
postNode.ampLink='https://amp.shuvayatra.org/post/'+post.id,
urls.push(postNode);
}
url=posts.next_page_url;
}
saveSitemap(urls);
function saveSitemap(urls){
let sitemap = sm.createSitemap({
hostname: 'https://shuvayatra.org',
cacheTime: 600000, //600 sec (10 min) cache purge period
urls: urls,
});
var stringData=sitemap.toString();
fs.writeFileSync("../webapp/sitemap.xml", stringData);
fs.writeFileSync("../webapp/sitemap.xml.gz", zlib.gzipSync(stringData));
console.log('sitemap saved...');
}