Directory listing

I am trying to build a simple photo portfolio site which posts all images in a directory. I don’t want to have to rewrite the html every time I add new photos. I’m very new to web development though so I don’t really know what I’m doing, but I have a little bit of coding experience.

My primary challenge here seems to be that I can’t collect the file listing in a directory, so I can’t use ajax jquery code to achieve this. I can’t use php for a static site here either, but php could apparently be used at build time, maybe to get a file directory listing, but I can’t seem to understand how to achieve that.

It seems there are a lot of other potential static site building solutions here but I really just want the most simple solution possible.

Summary:
What is the easiest way to get a list of files in a directory folder on a netlify site?

hi there, this thread should answer your question:

@perry Thanks very much for the reply. I did come across that but I was still a bit confused. I wanted a solution that happens at time of Netlifys build. When mjgs says he updated his static site generator, is that not on his end before Netlify builds the site? I don’t have a static site generator exactly, just some simple html code.

Do you recommend I try to implement Gatsby for this then? I wanted to confirm that’s a sensible approach before approaching it (since I don’t really know what I’m doing) but it seems Gatsby is meant for much more functionality than I need.

@disjunction You can create an index page listing all images in a folder pretty easily in Bridgetown (documentation here), and it doesn’t require needing to know much more than basic HTML. I imagine something similar could be done with Eleventy or Hugo. I personally think Gatsby would be way too complicated for your needs.

@jaredwhite Thanks! I’ll look into Bridgetown then to start. Gatsby did seem a bit much for this.

1 Like

@jaredwhite @perry
Ok I finally figured this out. This was much easier in php than using a static site generator. Turns out all I had to do was:
-Write my site in php doing what I needed to do (which was like 4 lines of code)
-Add a build.sh file with two lines: #!/bin/sh \ php index.php > “index.html”
-Add the build command: chmod a+x ./build.sh && ./build.sh

And a static site is generated from the php at build, and I don’t need to build it locally. I guess this should have been super obvious if I had known how to run a build shell script at deploy.

2 Likes

awesome! thanks for sharing your approach - i’m sure that will help other folks who are attempting the same thing :slight_smile: