-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.js
37 lines (37 loc) · 1.61 KB
/
posts.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
$(document).ready(function() {
$.ajax({
url: "/main.json",
type: "GET",
dataType: "json",
success: function(data) {
$("#title").html(data.name);
var pagesTemplate = Hogan.compile($("#pagesTemplate").html());
var pagesHtml = pagesTemplate.render({"pages": data.pages});
$("#pages").append(pagesHtml);
//path
var path = urlPath;
//path end
var now = 0;
for (var i = 0; i < data.posts.length; ++i)
if (path == data.posts[i].path)
now = i;
var post = data.posts[now];
var tmp = post.tags.split(" ");
var tags = [];
for (var i = 0; i < tmp.length; ++i)
if (tmp[i].length > 0)
tags.push({"name": tmp[i]});
var contentTemplate = Hogan.compile($("#content").html());
var contentHtml = contentTemplate.render({"title": post.title, "tags": tags, "date": post.date});
$("#main").prepend(contentHtml);
if (data.disqus_shortname.length > 0) {
var disqus_shortname = data.disqus_shortname;
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
}
}
});
});