-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
240 lines (206 loc) · 7.18 KB
/
index.html
File metadata and controls
240 lines (206 loc) · 7.18 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EndlessPixel's Portfolio</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}
body {
max-width: 1000px;
margin: 0 auto;
padding: 40px 20px;
background-color: #f8fafc;
color: #1e293b;
line-height: 1.6;
}
header {
text-align: center;
margin-bottom: 40px;
padding-bottom: 20px;
border-bottom: 1px solid #e2e8f0;
}
h1 {
font-size: 2.5rem;
color: #2563eb;
margin-bottom: 10px;
}
.subtitle {
color: #64748b;
font-size: 1.1rem;
}
.projects-section {
margin-top: 30px;
}
.section-title {
font-size: 1.8rem;
margin-bottom: 20px;
color: #1e293b;
display: flex;
align-items: center;
gap: 10px;
}
.section-title svg {
width: 24px;
height: 24px;
color: #2563eb;
}
.projects-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
}
.project-card {
background: #ffffff;
border-radius: 12px;
padding: 20px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease, box-shadow 0.2s ease;
border: 1px solid #e2e8f0;
}
.project-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.project-name {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 10px;
}
.project-name a {
color: #2563eb;
text-decoration: none;
}
.project-name a:hover {
text-decoration: underline;
}
.project-desc {
color: #64748b;
font-size: 0.95rem;
margin-bottom: 15px;
min-height: 40px;
}
.project-meta {
display: flex;
gap: 15px;
font-size: 0.85rem;
color: #94a3b8;
}
.loading, .error {
text-align: center;
padding: 40px;
font-size: 1.1rem;
}
.error {
color: #ef4444;
}
.no-projects {
text-align: center;
padding: 40px;
color: #64748b;
}
</style>
</head>
<body>
<header>
<h1>EndlessPixel</h1>
<p class="subtitle">Frontend & Tools Developer | 专注实用的小工具开发</p>
</header>
<section class="projects-section">
<h2 class="section-title">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path>
</svg>
My Projects
</h2>
<div id="projects-container" class="loading">
正在加载项目列表...
</div>
</section>
<script>
// 配置项
const CONFIG = {
username: 'EndlessPixel', // 你的GitHub用户名
// 过滤掉不需要展示的仓库(比如模板、测试仓库)
excludeRepos: ['EndlessPixel.github.io'], // 排除主页仓库本身
// 只展示公开仓库
onlyPublic: true
};
// 初始化项目列表
async function initProjects() {
const container = document.getElementById('projects-container');
try {
// 调用GitHub API获取仓库列表
const response = await fetch(`https://api.github.com/users/${CONFIG.username}/repos?sort=updated&direction=desc`);
// 处理API请求失败
if (!response.ok) {
throw new Error(`API请求失败:${response.status} ${response.statusText}`);
}
const repos = await response.json();
// 过滤仓库
const filteredRepos = repos.filter(repo => {
// 排除指定仓库
if (CONFIG.excludeRepos.includes(repo.name)) return false;
// 只展示公开仓库
if (CONFIG.onlyPublic && !repo.public) return false;
// 排除fork的仓库(可选,根据需要调整)
if (repo.fork) return false;
return true;
});
// 渲染项目列表
if (filteredRepos.length === 0) {
container.innerHTML = '<div class="no-projects">暂无公开项目 😊</div>';
return;
}
container.innerHTML = '';
container.classList.remove('loading');
container.classList.add('projects-grid');
filteredRepos.forEach(repo => {
const projectCard = createProjectCard(repo);
container.appendChild(projectCard);
});
} catch (error) {
// 处理异常
container.classList.remove('loading');
container.classList.add('error');
container.innerHTML = `
<div>加载项目失败:${error.message}</div>
<div style="margin-top:10px;font-size:0.9rem;">
可能原因:API限流、网络问题或用户名错误
</div>
`;
console.error('加载项目失败:', error);
}
}
// 创建单个项目卡片
function createProjectCard(repo) {
const card = document.createElement('div');
card.className = 'project-card';
// 处理空描述
const description = repo.description || '暂无项目描述';
// 格式化更新时间
const updatedAt = new Date(repo.updated_at).toLocaleDateString('zh-CN');
card.innerHTML = `
<h3 class="project-name">
<a href="${repo.html_url}" target="_blank" rel="noopener noreferrer">
${repo.name}
</a>
</h3>
<p class="project-desc">${description}</p>
<div class="project-meta">
<span>更新于:${updatedAt}</span>
<span>⭐ ${repo.stargazers_count || 0}</span>
</div>
`;
return card;
}
// 页面加载完成后初始化
window.addEventListener('DOMContentLoaded', initProjects);
</script>
</body>
</html>