-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
41 lines (40 loc) · 1.11 KB
/
index.html
File metadata and controls
41 lines (40 loc) · 1.11 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>devLog</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<header>
<a href="index.html"><h1>devLog</h1></a>
</header>
<ul class="post-list" id="post-list"></ul>
</main>
<script>
fetch('posts.json')
.then(res => res.json())
.then(posts => {
const ul = document.getElementById('post-list');
posts.forEach(post => {
const li = document.createElement('li');
li.innerHTML = `
<a href="post.html#${encodeURIComponent(post.file)}">${escapeHtml(post.title)}</a>
<div class="date">${escapeHtml(post.date)}</div>
`;
ul.appendChild(li);
});
})
.catch(err => {
document.getElementById('post-list').innerHTML = '<li>Failed to load posts.</li>';
});
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
</script>
</body>
</html>