Skip to content

Commit ad7741a

Browse files
committed
Merge pull request #3 from formula1/master
Stable and Working
2 parents 2bb840b + 1ecb55b commit ad7741a

28 files changed

+13023
-1081
lines changed

.gitmodules

Whitespace-only changes.

dist/api.js

Lines changed: 11842 additions & 0 deletions
Large diffs are not rendered by default.

dist/api.min.js

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/article.html

Lines changed: 330 additions & 248 deletions
Large diffs are not rendered by default.

dist/index.html

Lines changed: 269 additions & 224 deletions
Large diffs are not rendered by default.

html/article.ejs

Lines changed: 0 additions & 10 deletions
This file was deleted.

html/blog.ejs

Lines changed: 0 additions & 8 deletions
This file was deleted.

html/footerjs/bloglist.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
NodeOsBlog.controller('BlogListCtrl', function ($scope, $http) {
2-
$scope.uriPath = "/NodeOS/NodeOS/issues";
3-
$scope.blog = [];
4-
$scope.last = void(0);
5-
$scope.uriAsAuthority = uriAsAuthority;
6-
$scope.parseMarkdown = parseMarkdown;
7-
$scope.loadMore = function(page){
8-
if($scope.last && $scope.last < page) return;
9-
var i=0;
10-
var l=-1;
11-
$scope.uriAsAuthority(
12-
'https://api.github.com/repos'+$scope.uriPath+'?labels=blog&sort=updated&page='+page,
13-
function(uri){
14-
console.log("uri");
15-
$http.get(uri).success(function(data,status,headers) {
16-
console.log(headers);
17-
console.log(headers.link);
18-
if(!$scope.last) $scope.last = headers.link?headers.link.split("=").pop():1;
19-
l = data.length;
20-
if(i === l) return; //No more
21-
var iterator = function(item){
22-
$scope.blog.push(item);
23-
$scope.$apply();
24-
i++;
25-
if(i === l) return;
26-
$scope.parseMarkdown(data[i],iterator);
27-
};
28-
$scope.parseMarkdown(data[0],iterator);
29-
}).error(function(data, status, headers, config) {
30-
if(status === 403){
1+
2+
var listHandler;
3+
4+
jQuery(function($){
5+
listHandler = new Template(
6+
"script.template.bloglist",
7+
"div.container.bloglist"
8+
);
9+
listHandler._x = {
10+
uri: "https://api.github.com/repos/NodeOS/NodeOS/issues?labels=blog&sort=updated",
11+
last: void(0)
12+
};
13+
cacheOrUriIterator(
14+
"issue-list",
15+
{
16+
timestamp2URI: function(timestamp,next){
17+
var uri = listHandler._x.uri;
18+
if(timestamp) {
19+
var temp = new Date(timestamp+1000);
20+
uri += "&since="+(new Date(timestamp+1000)).toISOString();
21+
}
22+
user.asAuthority(uri,next);
23+
},
24+
prep: function(item, next){
25+
item.timestamp = (new Date(item.updated_at)).getTime();
26+
parseMarkdown(item,next);
27+
},
28+
ready: function(item,next){
29+
listHandler.add(item);
30+
setTimeout(next,1);
31+
},
32+
done: function(date){
33+
listHandler._x.last = date;
34+
},
35+
error: function(error){
36+
if(error.status && error.status === 403){
3137
add403();
3238
}else{
33-
errors.push({name:"Bad issues list request: "+status, message: data.message});
39+
addError(error);
3440
}
35-
});
36-
});
37-
};
38-
$scope.loadMore(1);
41+
}
42+
}
43+
);
3944
});

html/footerjs/blogsingle.js

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,68 @@
1-
var hash = document.location.toString().split("#")[1];
2-
NodeOsBlog.controller('BlogSingleCtrl', function ($scope, $http) {
3-
$scope.uriPath = "/NodeOS/NodeOS/issues/"+hash;
4-
$scope.blog = [];
5-
$scope.uriAsAuthority = uriAsAuthority;
6-
$scope.parseMarkdown = parseMarkdown;
1+
var num = (function(){
2+
var temp = document.location.href.split("#!")[1];
3+
console.log(temp);
4+
if(/[0-9]+/.test(temp)) return temp;
5+
temp = document.location.href.split("?");
6+
if(temp.length == 1){
7+
return add404();
8+
}
9+
temp = require("querystring").parse(temp[1]);
10+
if(!temp._escaped_fragment_){
11+
return add404();
12+
}
13+
return temp._escaped_fragment_;
14+
})();
715

8-
var markdown = require("markdown").markdown;
9-
$scope.uriAsAuthority('https://api.github.com/repos'+$scope.uriPath,function(uri){
10-
$http.get(uri).success(function(data,status,headers) {
11-
var l = data.labels.length;
12-
while(l--){
13-
if(data.labels[l].name === "blog"){
14-
break;
16+
var singleHandler;
17+
18+
jQuery(function($){
19+
if(!num) return;
20+
singleHandler = new Template(
21+
"script.template.blogsingle",
22+
"div.container.blogsingle"
23+
);
24+
singleHandler._x = {
25+
uri: "https://api.github.com/repos/NodeOS/NodeOS/issues/"+num,
26+
last: void(0)
27+
};
28+
cacheOrUriIterator(
29+
"issue-"+num,
30+
{
31+
timestamp2URI: function(timestamp,next){
32+
if(Date.now() - timestamp < 1000*60*60*24) return;
33+
user.asAuthority(singleHandler._x.uri,next);
34+
},
35+
prep: function(item, next){
36+
item.timestamp = Date.now();
37+
var l = item.labels.length;
38+
while(l--){
39+
if(item.labels[l].name === "blog"){
40+
break;
41+
}
42+
}
43+
if(l < 0){
44+
return addError({
45+
name:"Trying to load a non-blog?",
46+
message: "I technically can't stop you since this is clientside."+
47+
" Hopefully my code feels clean enough to hack"
48+
});
49+
}
50+
parseMarkdown(item,next);
51+
},
52+
ready: function(item,next){
53+
singleHandler.add(item);
54+
next();
55+
},
56+
done: function(date){
57+
singleHandler._x.last = date;
58+
},
59+
error: function(error){
60+
if(error.status && error.status === 403){
61+
add403();
62+
}else{
63+
addError(error);
1564
}
1665
}
17-
if(l < 0){
18-
return errors.push({
19-
name:"Trying to load a non-blog?",
20-
message: "I technically can't stop you since this is clientside."+
21-
" Hopefully my code feels clean enough to hack"
22-
});
23-
}
24-
$scope.parseMarkdown(data,function(item){
25-
$scope.blog.push(item);
26-
$scope.$apply();
27-
});
28-
}).error(function(data, status, headers, config) {
29-
if(status === 403){
30-
add403();
31-
}else{
32-
errors.push({name:"Bad issues list request: "+status, message: data.message});
33-
}
34-
});
35-
});
66+
}
67+
);
3668
});

html/footerjs/cacheOrLoad.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var async = require("async");
2+
3+
var in_memory = {};
4+
5+
function cacheOrUriIterator(cachename, itemCBs){
6+
var cached = localStorage.getItem(cachename);
7+
if(!cached || cached === "undefined" || cached === "[]" ){
8+
in_memory[cachename] = [];
9+
return UriIterator(cachename, void(0), itemCBs);
10+
}
11+
console.log("cached");
12+
cached = JSON.parse(cached);
13+
if(!Array.isArray(cached)){
14+
cached = [cached];
15+
}
16+
async.eachSeries(cached,
17+
itemCBs.ready,
18+
function(e,results){
19+
in_memory[cachename] = cached;
20+
UriIterator(cachename, cached[cached.length - 1].timestamp, itemCBs);
21+
});
22+
}
23+
24+
function UriIterator(cachename, timestamp, itemCBs){
25+
itemCBs.timestamp2URI(timestamp,function(uri){
26+
jQuery.get(uri).done(function(data){
27+
if(!Array.isArray(data)){
28+
data = [data];
29+
}
30+
async.eachSeries(data, function(item,next){
31+
itemCBs.prep(item,function(item){
32+
itemCBs.ready(item, next);
33+
});
34+
},function(err,results){
35+
if(err) return itemCBs.error(err);
36+
in_memory[cachename] = in_memory[cachename].concat(data);
37+
try{
38+
localStorage.setItem( cachename,JSON.stringify(in_memory[cachename]) );
39+
}catch(e){
40+
return itemCBs.error(e);
41+
}
42+
delete in_memory[cachename];
43+
if(data.length === 0){
44+
itemCBs.done(timestamp);
45+
}else{
46+
itemCBs.done(data[data.length -1].timestamp);
47+
}
48+
});
49+
}).fail(itemCBs.error);
50+
});
51+
}

html/footerjs/commentlist.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
1-
NodeOsBlog.controller('CommentListCtrl', function ($scope, $http) {
2-
$scope.uriPath = "/NodeOS/NodeOS/issues/"+hash+"/comments";
3-
$scope.blog = [];
4-
$scope.last = void(0);
5-
$scope.uriAsAuthority = uriAsAuthority;
6-
$scope.parseMarkdown = parseMarkdown;
7-
$scope.loadMore = function(page){
8-
if($scope.last && $scope.last < page) return;
9-
var i=0;
10-
var l=-1;
11-
$scope.uriAsAuthority(
12-
'https://api.github.com/repos'+$scope.uriPath+'?labels=blog&sort=created&page='+page,
13-
function(uri){
14-
$http.get(uri).success(function(data,status,headers) {
15-
if(!$scope.last) $scope.last = headers.link?headers.link.split("=").pop():1;
16-
l = data.length;
17-
if(i === l) return; //No more
18-
var iterator = function(item){
19-
$scope.blog.push(item);
20-
$scope.$apply();
21-
i++;
22-
if(i === l) return;
23-
$scope.parseMarkdown(data[i],iterator);
24-
};
25-
$scope.parseMarkdown(data[0],iterator);
26-
}).error(function(data, status, headers, config) {
27-
if(status === 403){
1+
2+
var commentHandler;
3+
4+
jQuery(function($){
5+
if(!num) return;
6+
commentHandler = new Template(
7+
"script.template.comments",
8+
"div.container.comments"
9+
);
10+
commentHandler._x = {
11+
uri: "https://api.github.com/repos/NodeOS/NodeOS/issues/"+num+"/comments",
12+
last: void(0)
13+
};
14+
cacheOrUriIterator(
15+
"issue-comments-"+num,
16+
{
17+
timestamp2URI: function(timestamp,next){
18+
var uri = commentHandler._x.uri;
19+
if(timestamp) {
20+
uri += "?since="+(new Date(timestamp+1000)).toISOString();
21+
}
22+
user.asAuthority(uri,next);
23+
},
24+
prep: function(item, next){
25+
item.timestamp = (new Date(item.created_at)).getTime();
26+
parseMarkdown(item,next);
27+
},
28+
ready: function(item,next){
29+
commentHandler.add(item);
30+
setTimeout(next,1);
31+
},
32+
done: function(date){
33+
commentHandler._x.last = date;
34+
},
35+
error: function(error){
36+
if(error.status && error.status === 403){
2837
add403();
2938
}else{
30-
errors.push({name:"Bad issues list request: "+status, message: data.message});
39+
addError(error);
3140
}
32-
});
33-
});
34-
};
35-
$scope.loadMore(1);
41+
}
42+
}
43+
);
3644
});

0 commit comments

Comments
 (0)