-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiteify.js
101 lines (89 loc) · 3.76 KB
/
siteify.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// alias phantomjs=/Applications/phantomjs.app//Contents/MacOS/phantomjs
// phantomjs siteify.js |tee siteify.log; tail -1 siteify.log >siteify.json
// var page, address, output, size;
var allSites = ['axialdev'];
//var allSites = ['axialdev','sebastien', 'estrimont', 'lepresident'];
var sitesFetched=false;
var renderedSites=[];
if (phantom.args.length > 0) {
console.log('Usage: siteify.js');
phantom.exit();
} else {
function render(status) {
if (status !== 'success') {
console.log('Unable to load the address:'+status);
console.log('Page address is ' + page.evaluate(function(){return ''+window.location;}));
//eatParts();
} else {
console.log(' got: '+page.evaluate(function(){return ''+window.location;}));
window.setTimeout(function () {
page.evaluate(function(){
window.pagesLeft=[];
$('div[data-role=page]').each(function(){
pagesLeft.push($(this).attr('id') )
});
pagesLeft = pagesLeft.filter(function(val){ return (val!='photozoom' && val!='splash');});
});
var renderingSite = renderedSites[renderedSites.length-1];
renderingSite.pages=[];
while (true) {
renderedPgId = page.evaluate(function(){
if (pagesLeft.length==0) return '';
$.mobile.defaultPageTransition='none';
var pgId = pagesLeft.shift();
$.mobile.changePage('#'+pgId);
return pgId;
});
if (renderedPgId==='' || renderedPgId==null ) break;
imageName = output+'-'+renderedPgId+'.png';
console.log(' rendering '+imageName);
page.render(imageName);
renderingSite.pages.push(imageName);
}
if (!sitesFetched){
var sites = page.evaluate(function(){
var sites=[];
var o = $.ajax({
url: '/api/site',
dataType: 'json',
async: false,
success: function(otherSites){
otherSites.forEach(function(site){
sites.push(site.name);
});
}
});
sites = sites.filter(function(val){ return (val!='axialdev');});
return sites;
});
allSites = allSites.concat(sites);
sitesFetched = true;
}
eatSite();
}, 500);
}
}
function eatSite(){
console.log('\n*** Remaining sites '+JSON.stringify(allSites)+'\n');
if (allSites.length>0){
address = allSites.shift();
renderedSites.push({name:address});
output='img/'+address;
address = 'http://'+address+'.ekomobi.com/';
//address = 'http://ekomobi.dev.axialdev.net/mobile.html?site='+address;
var url = address;
console.log(' fetch: '+url);
page = new WebPage();
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.viewportSize = { width: 320, height: 480 };
page.open(url, render );
} else {
console.log('we are done done: ');
console.log(JSON.stringify(renderedSites));
phantom.exit();
}
}
eatSite();
}