Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/AiverAiva/cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
AiverAiva committed Jun 24, 2024
2 parents da98fdd + 4f10012 commit 92d33e3
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
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;
}
```

0 comments on commit 92d33e3

Please sign in to comment.