-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.js
86 lines (66 loc) · 1.7 KB
/
notes.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
75
76
77
78
79
80
81
82
83
84
85
86
var notebook = document.getElementById("notepage")
var nav = document.getElementById("nav")
var notes = [
// {
// "date": "04-24-2024",
// "title": "hla retrospective",
// "url": "./notes/hla.md"
// },
{
"date": "09-18-2023",
"title": "my diary",
"url": "./notes/my_diary.md"
},
{
"date": "09-07-2023",
"title": "this is a website",
"url": "./notes/this_site.md"
},
]
// get each post from .md
const getNotes = async () => {
posts = []
const getContent = notes.map((note, id) => {
if (note.url) {
// create link
var link = document.createElement("a");
link.innerHTML = `<span>${note.title}</span> <span>${note.date}</span>`;
link.href = '#' + note.date;
nav.appendChild(link)
// for each post
return fetch(note.url)
.then((res) => res.text())
.then((text) => {
content = markdown(text);
posts.push([content, note.date, id])
})
}
})
return Promise.all(getContent).then(() => {
return posts
});
}
const buildNotes = async () => {
const posts = await getNotes();
console.log('retrieving posts')
// make sure in chronological order
posts.sort((a, b) => a[2] - b[2])
// render each post
posts.map((note) => {
// create post
var div = document.createElement("div");
div.classList.add('post')
// create anchor
var date = document.createElement("p");
date.innerHTML = note[1];
date.id = note[1];
date.classList.add('date')
div.appendChild(date)
// create content
var post = document.createElement("div");
post.innerHTML = note[0];
div.appendChild(post)
notebook.appendChild(div)
})
}
buildNotes();