-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
88 lines (79 loc) · 2.91 KB
/
index.html
File metadata and controls
88 lines (79 loc) · 2.91 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My GitHub Repo Navigator</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
padding-top: 4rem;
}
.file-item {
padding: 0.5rem;
border-bottom: 1px solid #ddd;
}
.file-icon {
margin-right: 10px;
}
.spinner-container {
height: 200px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="#">📁 GitHub File Navigator</a>
</div>
</nav>
<div class="container mt-4">
<div id="file-list" class="list-group">
<div class="text-center spinner-container">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading files...</span>
</div>
<p>Loading files from GitHub...</p>
</div>
</div>
</div>
<script>
const user = 'kingrdnd';
const repo = 'dosen';
const branch = 'main'; // or 'master' depending on your default branch
const apiUrl = `https://api.github.com/repos/${user}/${repo}/git/trees/${branch}?recursive=1`;
const baseUrl = `https://${user}.github.io/${repo}`;
fetch(apiUrl)
.then(response => {
if (!response.ok) throw new Error("Failed to load repository tree.");
return response.json();
})
.then(data => {
const files = data.tree.filter(item => item.type === "blob");
const listContainer = document.getElementById("file-list");
listContainer.innerHTML = ""; // clear loading spinner
files.forEach(file => {
const listItem = document.createElement("a");
listItem.className = "list-group-item list-group-item-action d-flex align-items-center file-item";
listItem.href = `${baseUrl}/${file.path}`;
listItem.target = "_blank";
const icon = document.createElement("i");
icon.className = "bi bi-file-earmark file-icon";
const text = document.createTextNode(file.path);
listItem.appendChild(icon);
listItem.appendChild(text);
listContainer.appendChild(listItem);
});
if (files.length === 0) {
listContainer.innerHTML = `<div class="alert alert-info">No files found in this repository.</div>`;
}
})
.catch(error => {
const listContainer = document.getElementById("file-list");
listContainer.innerHTML = `<div class="alert alert-danger">Error loading files: ${error.message}</div>`;
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>