Skip to content

Commit

Permalink
Add contentListUpdater.js to update content from the repository to th…
Browse files Browse the repository at this point in the history
…e GitHub page.
  • Loading branch information
sagarpatel288 committed Oct 7, 2024
1 parent c87bfae commit f646c7a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions contentListUpdater.js
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();

0 comments on commit f646c7a

Please sign in to comment.