-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
74 lines (59 loc) · 1.9 KB
/
script.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
// change if hosts md files someplace else :
var blogRoot = "https://trochr.github.io/blog/posts/";
function mdToHtml(text) {
var converter = new showdown.Converter();
return converter.makeHtml(text);
}
function loadDoc(myurl,cb) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
cb(xmlhttp.responseText);
}
}
xmlhttp.open("GET", myurl, true);
xmlhttp.send();
return xmlhttp.onreadystatechange();
}
function renderPost(p) {
document.getElementById("article").innerHTML = mdToHtml(p);
}
function showLayout(raw){
posts=raw.split('\n');
// keep only uncommented Markdown files
posts=posts.filter(function(a){return a.match(/^[^#].*\.md$/) != null;})
showList(posts);
showPost(getQueryVariable("a"));
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
console.log('Query variable %s not found', variable);
}
function showList(posts){
posts.forEach(function(e,i,n){
var li = document.createElement('li');
li.setAttribute('class','none');
document.getElementById("articles").appendChild(li);
li.innerHTML=li.innerHTML + "<a href=?a="+i+">"+e+"</a>";
});
}
function showPost(post){
loadDoc(blogRoot+posts[post], renderPost);
}
function init() {
// var posts=getPosts();
loadDoc(blogRoot+"list.txt", showLayout);
}
window.onload = init;