-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contentListUpdater.js to update content from the repository to th…
…e GitHub page.
- Loading branch information
1 parent
c87bfae
commit f646c7a
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
async function fetchFiles() { | ||
try { | ||
|
||
const response = await fetch('https://api.github.com/repos/sagarpatel288/kotlinDSAWithIntelliJIdea/contents'); | ||
|
||
// Check if response is successful | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch repository content'); | ||
} | ||
|
||
const data = await response.json(); | ||
const fileList = document.getElementById('file-list'); | ||
|
||
// Filter Kotlin files and sort them by name | ||
const ktFiles = data.filter(item => item.name.endsWith('.kt')); | ||
ktFiles.sort((a, b) => a.name.localeCompare(b.name)); | ||
|
||
// Create links for each Kotlin file | ||
ktFiles.forEach(file => { | ||
const fileLink = document.createElement('a'); | ||
fileLink.href = file.html_url; // GitHub link to the file | ||
fileLink.textContent = file.name; | ||
fileLink.target = '_blank'; | ||
fileList.appendChild(fileLink); | ||
fileList.appendChild(document.createElement('br')); | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching files:', error); | ||
document.getElementById('file-list').textContent = 'Error loading files.'; | ||
} | ||
} | ||
|
||
// Execute the function to fetch and display files | ||
fetchFiles(); |