-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
67 lines (63 loc) · 2.38 KB
/
index.html
File metadata and controls
67 lines (63 loc) · 2.38 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Truth of Code</title>
<style>
body { font-family: system-ui, sans-serif; margin: 0; padding: 2rem; line-height: 1.6; background: #fafafa; color: #222; }
h1, h2 { color: #333; }
.header { border-bottom: 2px solid #ccc; padding-bottom: 2rem; margin-bottom: 2rem; }
.posts li { margin: 0.5rem 0; }
.date { color: gray; font-size: 0.9em; margin-left: 0.5rem; }
a { text-decoration: none; color: #0077cc; }
a:hover { text-decoration: underline; }
</style>
</head>
<body>
<div id="header" class="header">Loading...</div>
<h2>Recent Posts</h2>
<ul id="posts" class="posts"></ul>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
const username = 'TruthOfCode';
const repo = 'TruthOfCode.github.io';
const postsPath = 'posts';
// Render the top section (about.md)
fetch('about.md')
.then(r => r.text())
.then(md => {
document.getElementById('header').innerHTML = marked.parse(md);
});
// Fetch post list from GitHub API
fetch(`https://api.github.com/repos/${username}/${repo}/contents/${postsPath}`)
.then(r => r.json())
.then(files => {
const list = document.getElementById('posts');
files.filter(f => f.name.endsWith('.md')).forEach(file => {
// Get last commit date
fetch(file.git_url)
.then(r => r.json())
.then(data => {
const date = new Date(data.committer.date).toLocaleString();
const name = file.name.replace('.md', '');
const link = `${postsPath}/${file.name}`;
const li = document.createElement('li');
li.innerHTML = `<a href="${link}">${name}</a> <span class="date">${date}</span>`;
list.appendChild(li);
})
.catch(() => {
const name = file.name.replace('.md', '');
const link = `${postsPath}/${file.name}`;
const li = document.createElement('li');
li.innerHTML = `<a href="${link}">${name}</a>`;
list.appendChild(li);
});
});
})
.catch(err => {
document.getElementById('posts').innerHTML = '<li>Could not load posts.</li>';
});
</script>
</body>
</html>