-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
75 lines (61 loc) · 2.06 KB
/
index.html
File metadata and controls
75 lines (61 loc) · 2.06 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
---
layout: default
---
<ul id="gist-list">Loading...</ul>
<script>
const username = "Andre-Tan"; // CHANGE THIS
const gistAPI = `https://api.github.com/users/${username}/gists?per_page=10`; // fetch 10 to check if >5 exist
fetch(gistAPI)
.then(res => res.json())
.then(gists => {
const list = document.getElementById("gist-list");
const moreLink = document.getElementById("more-link");
list.innerHTML = "";
gists.slice(0, 5).forEach(gist => {
const desc = gist.description || "No description";
const url = gist.html_url;
const files = Object.keys(gist.files).join(", ");
const date = gist.updated_at.slice(0, 10);
const article = document.createElement("article");
article.className = "gist-item";
const title = document.createElement("h3");
title.innerHTML = `<a href="${url}" target="_blank">${files}</a>`;
const description = document.createElement("p");
description.textContent = desc;
const dateTag = document.createElement("small");
dateTag.textContent = `Last updated: ${date}`;
article.appendChild(title);
article.appendChild(description);
article.appendChild(dateTag);
list.appendChild(article);
});
if (gists.length > 5) {
moreLink.innerHTML = `<a class="button" href="https://gist.github.com/${username}" target="_blank">View all gists →</a>`;
}
})
.catch(() => {
document.getElementById("gist-list").innerHTML = "<li>Failed to load gists.</li>";
});
</script>
<div id="more-link"></div>
<style>
.gist-item {
margin-bottom: 1.2em;
border-bottom: 1px solid #eee;
padding-bottom: 0.5em;
}
.gist-item h3 {
font-size: 1.1rem;
margin: 0 0 0.2em;
}
.gist-item p {
font-size: 0.95rem;
margin: 0.25em 0 0.5em;
}
.gist-item small {
font-size: 0.8rem;
color: #888;
display: block;
margin-top: 0.5em;
}
</style>