Skip to content

Get size of build to display on page #3158

Answered by Akashic101
Akashic101 asked this question in Q&A
Discussion options

You must be logged in to vote

I figured out it, eleventy.after only provides the result of what has been written to disk which is why replacing the word only changed it there. With following function it overwrites the file with the replaced placeholder:

const fs = require('fs');
const path = require('path');

function getFolderSize(folderPath) {
	let totalSize = 0;

	function traverseDirectory(currentPath) {
		const files = fs.readdirSync(currentPath);

		files.forEach((file) => {
			const filePath = path.join(currentPath, file);
			const stats = fs.statSync(filePath);

			if (stats.isDirectory()) {
				traverseDirectory(filePath);
			} else {
				totalSize += stats.size;
			}
		});
	}

	traverseDirectory(folderPath);
	

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Akashic101
Comment options

@Akashic101
Comment options

Answer selected by Akashic101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants