|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Truth of Code</title> |
| 7 | + <style> |
| 8 | + body { font-family: system-ui, sans-serif; margin: 0; padding: 2rem; line-height: 1.6; background: #fafafa; color: #222; } |
| 9 | + h1, h2 { color: #333; } |
| 10 | + .header { border-bottom: 2px solid #ccc; padding-bottom: 2rem; margin-bottom: 2rem; } |
| 11 | + .posts li { margin: 0.5rem 0; } |
| 12 | + .date { color: gray; font-size: 0.9em; margin-left: 0.5rem; } |
| 13 | + a { text-decoration: none; color: #0077cc; } |
| 14 | + a:hover { text-decoration: underline; } |
| 15 | + </style> |
| 16 | +</head> |
| 17 | +<body> |
| 18 | + <div id="header" class="header">Loading...</div> |
| 19 | + |
| 20 | + <h2>Recent Posts</h2> |
| 21 | + <ul id="posts" class="posts"></ul> |
| 22 | + |
| 23 | + <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> |
| 24 | + <script> |
| 25 | + const username = 'TruthOfCode'; |
| 26 | + const repo = 'TruthOfCode.github.io'; |
| 27 | + const postsPath = 'posts'; |
| 28 | + |
| 29 | + // Render the top section (about.md) |
| 30 | + fetch('about.md') |
| 31 | + .then(r => r.text()) |
| 32 | + .then(md => { |
| 33 | + document.getElementById('header').innerHTML = marked.parse(md); |
| 34 | + }); |
| 35 | + |
| 36 | + // Fetch post list from GitHub API |
| 37 | + fetch(`https://api.github.com/repos/${username}/${repo}/contents/${postsPath}`) |
| 38 | + .then(r => r.json()) |
| 39 | + .then(files => { |
| 40 | + const list = document.getElementById('posts'); |
| 41 | + files.filter(f => f.name.endsWith('.md')).forEach(file => { |
| 42 | + // Get last commit date |
| 43 | + fetch(file.git_url) |
| 44 | + .then(r => r.json()) |
| 45 | + .then(data => { |
| 46 | + const date = new Date(data.committer.date).toLocaleString(); |
| 47 | + const name = file.name.replace('.md', ''); |
| 48 | + const link = `${postsPath}/${file.name}`; |
| 49 | + const li = document.createElement('li'); |
| 50 | + li.innerHTML = `<a href="${link}">${name}</a> <span class="date">${date}</span>`; |
| 51 | + list.appendChild(li); |
| 52 | + }) |
| 53 | + .catch(() => { |
| 54 | + const name = file.name.replace('.md', ''); |
| 55 | + const link = `${postsPath}/${file.name}`; |
| 56 | + const li = document.createElement('li'); |
| 57 | + li.innerHTML = `<a href="${link}">${name}</a>`; |
| 58 | + list.appendChild(li); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }) |
| 62 | + .catch(err => { |
| 63 | + document.getElementById('posts').innerHTML = '<li>Could not load posts.</li>'; |
| 64 | + }); |
| 65 | + </script> |
| 66 | +</body> |
| 67 | +</html> |
0 commit comments