I am currently trying to make my first website where i plan to put my photos for everyone to see, it is going great but i am now encountering a pretty important problem : the html code requires me to make a div for each image i want to put in the site, and with hundreds of images that can be pretty hard.
My first idea to overcome this was to make a JavaScript script to make it iterate through a folder and slap every image onto a grid, kinda like this:
function getFolderSize(path) {
const count = 0;
for (file in path) {
count++;
}
return count;
}
for (let i = 0, i < getFolderSize(path), i++) {
const cell = document.createElement('div');
cell.class = "cell";
cell.id = "cell_" + i;
document.body.appendChild(cell);
const image = document.createElement('img');
image.src = path/i.jpg;
image.class = "image";
cell.appendChild(image)
}
I made every cell a div to add the possibility to add text under the images in the future, but that is not the problem, instead, was wondering how to make a code to know how many files there are in the folder where i keep my images to be able to iterate through them and put them all on the screen.
All the solutions i have found are using node.js or other things, but i am new to javascript and i can't get that to work on a website.
I would be very grateful if anybody could find a solution to this, possibly beginner friendly so i can learn something from this.
Thanks.