-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchBlogs.js
33 lines (29 loc) · 905 Bytes
/
fetchBlogs.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
var links = [];
fetch("./bloglist.txt")
.then(x => x.text())
.then(data => {
links = data.replace(/\r\n/g, "\n").split("\n");
links = cleanLinks(links);
links.forEach(element => appendBlog(element));
});
function cleanLinks(links) {
for (let i = 0; i < links.length; i++) {
if (links[i][0] == "#") {
delete links[i];
}
}
links = [...new Set(links)];
return links;
}
function appendBlog(blogFile) {
if (blogFile) {
let tag = document.createElement("a");
let title = blogFile.replace(/^.*[\\\/]/, "").replace(/\.[^/.]+$/, "");
let text = document.createTextNode(title);
tag.appendChild(text);
tag.href = blogFile;
let element = document.getElementById("blogsContainer");
element.appendChild(tag);
element.appendChild(document.createElement("br"));
}
}