-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
82 lines (64 loc) · 2.75 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Git Diary</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura.css" type="text/css">
</head>
<body>
<h1>Git Diary</h1>
<p>
Hi! My name is Pedro Boueke (a.k.a <a href="https://pboueke.github.io/b/">pboueke</a>). This diary/blog is an example
of the git diary project. It is managed by an instance of the
<a href="https://github.com/pboueke/git-diary-api">git diary api</a>.
You can learn more about this project <a href="https://github.com/pboueke/git-diary">here</a>.
</p>
<div id="container">
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/8.4.2/markdown-it.min.js" type="text/javascript"></script>
<script>
const processPosts = async names => {
const htmls = names.filter(n => n !== "index")
.sort((a,b) => a > b ? -1 : 1)
.map(async n => await fetchPost(n))
.map(async r => await builPostObject(r))
.map(async o => await buildPostHTML(o))
Promise.all(htmls)
.then(htmls => htmls.reduce((a,b) => a + b))
.then(html => document.getElementById("container").innerHTML = html)
}
const fetchPost = async name => {
const text = await (await fetch("posts/" + name + ".md")).text()
return { text, name }
}
const builPostObject = async file => {
const f = await file
const title = f.text.split('\n')[0]
return {
title,
body: f.text.replace(title,""),
date: new Date(f.name.substring(0,10).replace(/-/g, "/")).toDateString()
}
}
const buildPostHTML = async postObject => {
const md = window.markdownit();
const obj = await postObject
let string = "<div>"
string += "<br>"
string += "<h2>" + obj.title + "</h2>"
string += "<p>" + obj.date + "</p>"
string += "<hr>"
string += md.render(obj.body)
string += "</div>"
return string
}
(async () => {
const names = await fetch("posts/index.json")
processPosts(await names.json())
})()
</script>
</html>