-
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.
Merge branch 'main' of https://github.com/AiverAiva/cdn
- Loading branch information
Showing
1 changed file
with
32 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,4 +1,35 @@ | ||
# cdn | ||
|
||
A file tree system made with very easy mechanic. Using Github Actions for updating. | ||
I made this due to the scarcity of these kind of resources we are able to find on the internet, there are prob some exist libraries that I didnt found. | ||
But anyways it took me a few minutes to make this simple script, which fits all my requirements I need and it is pretty need | ||
|
||
# Explaination | ||
|
||
This function basically creates the required html code for the website to work | ||
It recursively searchs files in `src/` | ||
and making its path for the later using of turning the paths into code | ||
Thats what this function does. | ||
|
||
```js | ||
function generateFileTree(dir) { | ||
const files = fs.readdirSync(dir); | ||
|
||
let fileTree = '<ul>'; | ||
files.forEach((file) => { | ||
const fullPath = path.join(dir, file); | ||
const relativePath = path.relative(rootDir, fullPath); | ||
const isDirectory = fs.statSync(fullPath).isDirectory(); | ||
|
||
due to how funni i made it im not going to explain how this work since its all basic knowledge to coding. | ||
if (isDirectory) { | ||
fileTree += `<li><details><summary><i class="fas fa-folder"></i> ${file}</summary>`; | ||
fileTree += generateFileTree(fullPath); | ||
fileTree += '</details></li>'; | ||
} else { | ||
fileTree += `<li><a href="${rootDir + relativePath}"><i class="fas fa-file"></i> ${file}</a></li>`; | ||
} | ||
}); | ||
fileTree += '</ul>'; | ||
return fileTree; | ||
} | ||
``` |