Skip to content

Commit

Permalink
Get size of repo folder and add to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCogley committed Nov 19, 2024
1 parent 6f3fdb5 commit 12dcfda
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
70 changes: 70 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,29 @@ const holidays = await response.json();
export {
holidays,
};

import { join } from "https://deno.land/std/path/mod.ts";

async function getFolderSize(path: string): Promise<number> {
let totalSize = 0;

for await (const entry of Deno.readDir(path)) {
const entryPath = join(path, entry.name);
const info = await Deno.stat(entryPath);

if (info.isFile) {
totalSize += info.size;
} else if (info.isDirectory) {
totalSize += await getFolderSize(entryPath);
}
}

return totalSize;
}

const folderPath = "./";
getFolderSize(folderPath).then(size => {
console.log(`Total size: ${size/1024/1024} MB`);
});
export const repoSizeLong = await getFolderSize(folderPath);
export const repoSizeMB = Math.trunc(repoSizeLong/1024/1024);
1 change: 1 addition & 0 deletions src/repo-readme.vto
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Many thanks to [Óscar Otero](https://oscarotero.com/), creator of Lume, [Lume C
| Item | Value |
| --- | --- |
| Total Files | {{ search.files("").length }} |
| Repo Size in MB | {{ repoSizeMB }} |

0 comments on commit 12dcfda

Please sign in to comment.