diff --git a/.github/workflows/content_list_page.yml b/.github/workflows/content_list_page.yml new file mode 100644 index 0000000..14281c1 --- /dev/null +++ b/.github/workflows/content_list_page.yml @@ -0,0 +1,86 @@ +name: Update GitHub Pages + +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +jobs: + update-content: + runs-on: ubuntu-latest + + steps: + - name: Configure Git user + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + + # Step 1: Checkout the 'github_pages_from_main' branch + - name: Checkout github_pages_from_main branch + uses: actions/checkout@v4 + with: + ref: github_pages_from_main + + - name: Configure Git Pull Strategy + run: git config pull.rebase false # Use 'true' for rebase or 'ff only' for fast-forward only + + # Step 2: Merge changes from 'main' into 'github_pages_from_main' + - name: Merge main into github_pages_from_main + run: | + git remote set-url origin https://x-access-token:${{ secrets.TOKEN }}@github.com/${{ github.repository }}.git + git checkout github_pages_from_main + git pull origin main --allow-unrelated-histories -X theirs + + # Step 3: Ensure files.json exists + - name: Create files.json if it does not exist + run: | + if [ ! -f files.json ]; then + echo "[]" > files.json + fi + + # Step 4: Run the JavaScript script to update the files.json + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies + run: npm install node-fetch + + - name: Run update script + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + run: node updateContentGitHubActionsGitHubPages.mjs + + # Step 5: Commit and push changes to github_pages_from_main + - name: Commit and push changes to github_pages_from_main + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add files.json + git commit -m 'Update files.json with latest Kotlin files' || echo "No changes to commit" + git push https://x-access-token:${{ secrets.TOKEN }}@github.com/${{ github.repository }}.git HEAD:github_pages_from_main + + deploy: + needs: update-content + runs-on: ubuntu-latest + + steps: + # Step 6: Deploy the content to GitHub Pages + - name: Checkout github_pages_from_main branch + uses: actions/checkout@v3 + with: + ref: github_pages_from_main + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.TOKEN }} + publish_dir: ./kotlinDSAWithIntellijIdea + destination_branch: gh-pages # Specify the branch to deploy to \ No newline at end of file diff --git a/files.json b/files.json new file mode 100644 index 0000000..2230eb4 --- /dev/null +++ b/files.json @@ -0,0 +1,142 @@ +[ + { + "name": "array.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level02DataTypes/array.kt" + }, + { + "name": "scanner.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level06/scanner.kt" + }, + { + "name": "maxPairProduct.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level10/maxPairProduct.kt" + }, + { + "name": "010nthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/010nthFibonacci.kt" + }, + { + "name": "012nthFibonacciModulo.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/012nthFibonacciModulo.kt" + }, + { + "name": "013nthFibonacciModuloArithmetically.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/013nthFibonacciModuloArithmetically.kt" + }, + { + "name": "015lastDigitOfNthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/015lastDigitOfNthFibonacci.kt" + }, + { + "name": "020hugeNthFibonacciModuloDynamic.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/020hugeNthFibonacciModuloDynamic.kt" + }, + { + "name": "028naiveLastDigit4SumOfNthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/028naiveLastDigit4SumOfNthFibonacci.kt" + }, + { + "name": "030lastDigit4sumOfNthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/030lastDigit4sumOfNthFibonacci.kt" + }, + { + "name": "035lastDigitOfPartialSumOfNthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/035lastDigitOfPartialSumOfNthFibonacci.kt" + }, + { + "name": "036lastDigitOfPartialSumOfNthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/036lastDigitOfPartialSumOfNthFibonacci.kt" + }, + { + "name": "040lastDigitOfSumOfSquareOfNthFibonacci.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/040lastDigitOfSumOfSquareOfNthFibonacci.kt" + }, + { + "name": "05naivePrintFibonacciUpTo.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/05naivePrintFibonacciUpTo.kt" + }, + { + "name": "070gcdOrHcfUsingEuclid.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/070gcdOrHcfUsingEuclid.kt" + }, + { + "name": "071gcdOrHcfUsingEuclid.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/071gcdOrHcfUsingEuclid.kt" + }, + { + "name": "080lcmUsingEuclideanTheory.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/080lcmUsingEuclideanTheory.kt" + }, + { + "name": "090Josephus.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/090Josephus.kt" + }, + { + "name": "091josephusProblem.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/091josephusProblem.kt" + }, + { + "name": "100RangeSumQueryImmutable.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level20Week2AlgorithmicWarmUp/100RangeSumQueryImmutable.kt" + }, + { + "name": "010MoneyChangeDenomination.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/010MoneyChangeDenomination.kt" + }, + { + "name": "020maximumLoot.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/020maximumLoot.kt" + }, + { + "name": "030carFueling.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/030carFueling.kt" + }, + { + "name": "032carFueling2ndWay.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/032carFueling2ndWay.kt" + }, + { + "name": "040maximumDotProductOf2Sequences.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/040maximumDotProductOf2Sequences.kt" + }, + { + "name": "050minimumPointsToCoverUnionSegments.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/050minimumPointsToCoverUnionSegments.kt" + }, + { + "name": "060distinctSummandsProblem.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/060distinctSummandsProblem.kt" + }, + { + "name": "070largestConcatenatedNumber.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level30Module3AlgorithmExercise/070largestConcatenatedNumber.kt" + }, + { + "name": "010selectionSortExample.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/010selectionSortExample.kt" + }, + { + "name": "020mergeSortExample.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/020mergeSortExample.kt" + }, + { + "name": "030mergeSortClean.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/030mergeSortClean.kt" + }, + { + "name": "040countSortExample.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/040countSortExample.kt" + }, + { + "name": "050countSortClean.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/050countSortClean.kt" + }, + { + "name": "060quickSort1.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/060quickSort1.kt" + }, + { + "name": "070quickSort1Clean.kt", + "url": "https://github.com/sagarpatel288/kotlinDSAWithIntellijIdea/blob/main/src/level40Module4AlgorithmExercise/070quickSort1Clean.kt" + } +] \ No newline at end of file diff --git a/fonts/Roboto.woff2 b/fonts/Roboto.woff2 new file mode 100644 index 0000000..07f2ea6 Binary files /dev/null and b/fonts/Roboto.woff2 differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..dd7d667 --- /dev/null +++ b/index.html @@ -0,0 +1,141 @@ + + + + + + Kotlin DSA Practice Files + + + + + + +

Kotlin DSA Practice Files

+
Loading...
+ + + + + + + +
+ +
+ + \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..e9ae591 --- /dev/null +++ b/styles.css @@ -0,0 +1,52 @@ +@font-face { + font-family: 'Roboto'; + src: url('fonts/Roboto.woff2') format('woff2'); + font-weight: 400; + font-style: normal; +} + + +body { + font-family: 'Roboto', Arial, sans-serif; + background-color: #f4f4f4; + color: #333; + line-height: 1.6; + margin: 0; + padding: 20px; +} + +h1 { + color: #444; + font-size: 2.5em; + text-align: center; + margin-bottom: 20px; +} + +a { + color: #007bff; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +#file-list { + max-width: 800px; + margin: 20px auto; + padding: 20px; + background-color: #fff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +.file-link { + display: block; + padding: 10px; + border-bottom: 1px solid #eaeaea; + color: #333; +} + +.file-link:last-child { + border-bottom: none; +} diff --git a/updateContentBrowserScript.js b/updateContentBrowserScript.js new file mode 100644 index 0000000..a422dcf --- /dev/null +++ b/updateContentBrowserScript.js @@ -0,0 +1,78 @@ +document.addEventListener('DOMContentLoaded', async () => { + const fileList = document.getElementById('file-list'); + const sortOptions = document.getElementById('sort-options'); + const loader = document.getElementById('loader'); + const messageBox = document.getElementById('message-box'); + const messageText = document.getElementById('message-text'); + const closeMessageButton = document.getElementById('close-message'); + + let kotlinFiles = []; + + // Show the loader until the files are loaded + loader.style.display = 'block'; + + // Close the message box when the close button is clicked + closeMessageButton.addEventListener('click', () => { + messageBox.style.display = 'none'; + }); + + async function loadFiles() { + try { + const timestamp = new Date().getTime(); // Prevent caching + const response = await fetch(`files.json`); + if (!response.ok) throw new Error('Failed to fetch files'); + + kotlinFiles = await response.json(); + renderFileList(kotlinFiles); + } catch (error) { + console.error('Error loading files:', error); + showMessage('Error loading files. Please try again later.', 'error'); + } finally { + loader.style.display = 'none'; + } + } + + function renderFileList(files) { + fileList.innerHTML = ''; + files.forEach(file => { + const link = document.createElement('a'); + link.href = file.url; + link.textContent = file.name; + link.className = 'file-link'; + fileList.appendChild(link); + }); + } + + function showMessage(message, type) { + messageText.textContent = message; + messageBox.className = `message-box ${type}`; + messageBox.style.display = 'block'; + } + + // Add sorting functionality + sortOptions.addEventListener('change', () => { + const option = sortOptions.value; + let sortedFiles = [...kotlinFiles]; + + switch (option) { + case 'ascending': + sortedFiles.sort((a, b) => a.name.localeCompare(b.name)); + break; + case 'descending': + sortedFiles.sort((a, b) => b.name.localeCompare(a.name)); + break; + case 'latest': + sortedFiles.sort((a, b) => new Date(b.date) - new Date(a.date)); + break; + case 'oldest': + sortedFiles.sort((a, b) => new Date(a.date) - new Date(b.date)); + break; + default: + break; + } + + renderFileList(sortedFiles); + }); + + await loadFiles(); +}); \ No newline at end of file diff --git a/updateContentGitHubActionsGitHubPages.mjs b/updateContentGitHubActionsGitHubPages.mjs new file mode 100644 index 0000000..a440fc2 --- /dev/null +++ b/updateContentGitHubActionsGitHubPages.mjs @@ -0,0 +1,54 @@ +/** +* contentListUpdater.js (Node.js environment) +* This script should run in a Node.js environment (like GitHub Actions) to fetch data from the GitHub API +* and create files.json. +* It uses fs to write files.json and process.env.GITHUB_TOKEN for authentication. +* Environment Separation: Ensure server-side code runs in GitHub Actions and client-side code runs in the browser. +* Sorting and UI: Handle sorting and UI interactions in the browser. +* Loading and Messages: Use the browser script to manage loading states and display messages. +* This separation ensures that each part of your application runs in the correct environment without errors. +*/ +import fs from 'fs'; +import fetch from 'node-fetch'; // Use 'import' instead of 'require' + +(async () => { + const username = 'sagarpatel288'; + const repo = 'kotlinDSAWithIntellijIdea'; + const accessToken = process.env.GITHUB_TOKEN; + let kotlinFiles = []; + + async function fetchKotlinFiles(path = '') { + try { + const headers = { + Authorization: `Bearer ${accessToken}` + }; + const response = await fetch(`https://api.github.com/repos/${username}/${repo}/contents/${path}?t=${new Date().getTime()}`, { headers }); + if (!response.ok) { + throw new Error(`Network response was not ok for path: ${path}`); + } + + const data = await response.json(); + console.log('Fetched Data:', data); // Log fetched data + if (Array.isArray(data)) { + for (const item of data) { + console.log('Processing Item:', item); // Log each item being processed + if (item.type === 'dir') { + await fetchKotlinFiles(item.path); + } else if (item.type === 'file' && item.name.endsWith('.kt')) { + kotlinFiles.push({ name: item.name, url: item.html_url }); + } + } + } + } catch (error) { + console.error(`Error fetching file list for path ${path}:`, error); + } + } + + try { + await fetchKotlinFiles(); + fs.writeFileSync('files.json', JSON.stringify(kotlinFiles, null, 2)); + console.log('files.json has been saved with the latest Kotlin files.'); + } catch (error) { + console.error('Error writing to files.json:', error); + } +})(); \ No newline at end of file