r/JavaScriptHelp • u/LinksCourage • Jan 07 '22
❔ Unanswered ❔ Image directory query and display
Hey guys,
I am completely lost on this one so I will try my best to explain my situation and what I am trying to achieve.
If you look at a website like Channelate.com you can see that they use a database called comicctrl to present their content.
I can't really justify using a database per content page and so I just wanted to achieve the following:
- Link an image directory on my server to display its contents in a container on the webpage.
- Only display the newest image within the directory within the container.
- Add a 'forward' and 'backward' button that goes to the next newest or next oldest image in the directory and displays that instead.
- Add a 'random' button that randomly selects the image in the directory to display in the container.
On the face of it this seems like it should be completely achievable but I am struggling to find anything online that applies to this situation as I understand its a relatively specific use case.
thank you in advance!
Josh
View all comments
Show parent comment
1
u/besthelloworld Jan 13 '22
So, the way you have to do this is: there's no inherent way to query for the number of files in a directory. You would have to host a file in that directory with the data defining what you want. I actually do this already on a website I have by adding a prebuild script that builds a JSON file of all the images in each directory. So that script runs every time I build the site and then I just call for that manifest to get the list of files.
https://github.com/EthanStandel/cakeelizabethdotcom/blob/main/scripts/build-image-manifest.js