-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistFiles.js
More file actions
30 lines (26 loc) · 1.13 KB
/
listFiles.js
File metadata and controls
30 lines (26 loc) · 1.13 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
async function listFiles() {
const repo = 'synuora/synuora.github.io'; // Replace with your GitHub username and repository name
const branch = 'main'; // Replace with your default branch if different
const apiURL = `https://api.github.com/repos/${repo}/git/trees/${branch}?recursive=1`;
try {
const response = await fetch(apiURL);
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.json();
const fileList = document.getElementById('fileList');
data.tree.forEach(file => {
if (file.type === 'blob') {
const listItem = document.createElement('li');
const link = document.createElement('a');
link.href = file.path;
link.textContent = file.path;
listItem.appendChild(link);
fileList.appendChild(listItem);
}
});
} catch (error) {
console.error('There has been a problem with your fetch operation:', error);
}
}
document.addEventListener('DOMContentLoaded', listFiles);