-
Notifications
You must be signed in to change notification settings - Fork 3
/
postindextemplate.html
63 lines (49 loc) · 2.01 KB
/
postindextemplate.html
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
<!DOCTYPE html>
<html>
<head>
<title>{0}'s Preposter.us Blog</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width; initial-scale=1.0;">
<link rel="stylesheet" href="css/reset.css" media="all" />
<link rel="stylesheet" href="css/single-col.css" media="all" />
</head>
<body>
<section>
<header>
<h1><span>{0}'s</span> Preposter.us Blog</h1>
<h2><span>Posts</span></h2>
</header>
<article class="cols">
<ul id="postlist"></ul>
</article>
<br>
<div class="footer">
hosted by <a style="color: red; text-decoration: none" href="https://preposter.us">preposter.us</a>
</div>
</section>
<script>
var serverProtocol = location.protocol;
var serverHost = location.hostname;
var serverPort = location.port;
//var serverURL = serverProtocol + '//' + serverHost + ':' + serverPort;
//var postListURL = serverURL + '/{1}/posts.json';
var postListURL = 'posts.json';
var postListReq = new XMLHttpRequest();
postListReq.onload = renderList;
postListReq.open('GET', postListURL, true);
postListReq.send();
function renderList(){
var posts = JSON.parse(this.responseText).posts;
posts.sort(function(a,b) { return Date.parse(b.post.date) - Date.parse(a.post.date) } )
var postListHTML = '';
for(var i=0;i<posts.length;i++){
var postDate = new Date(posts[i].post.date);
var dateString = (postDate.getMonth() + 1) + '/' + postDate.getDate() + '/' + postDate.getFullYear();
postListHTML = postListHTML + '<li>' + dateString + ' <a href="' + posts[i].post.slug + '.html">' + posts[i].post.title + '</a></li>\n';
}
var postList = document.getElementById('postlist');
postList.innerHTML = postListHTML;
}
</script>
</body>
</html>