-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.js
31 lines (29 loc) · 988 Bytes
/
blog.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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>博客</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>📖 博客文章</h1>
<ul id="post-list"></ul>
</div>
<script>
async function fetchPosts() {
let repo = "你的GitHub用户名/你的仓库名";
let response = await fetch(`https://api.github.com/repos/${repo}/contents/post`);
let files = await response.json();
let postList = document.getElementById("post-list");
files.forEach(file => {
let listItem = document.createElement("li");
listItem.innerHTML = `<a href="post.html?file=${file.name}">${file.name}</a>`;
postList.appendChild(listItem);
});
}
fetchPosts();
</script>
</body>
</html>