Listing files in directory

Hi, I have a quick question.

Is it possible to make Jekyll display a file overview when accessing a directory path? Example:

  |  +--some-file.html
  |  +--another-file.html

When running bundle exec jekyll serve, the file will be accessible. However, I want a list of files when accessing

One possibility is to create a file manually, containing a link to every file in that directory. But is there a possibility to auto-generate a page, or (even better), use some browser built-in (like when accessing file:///var/log)?

Thank you for your help!

If you want to do that with a built site , I can recommend python built server. It gives you a folder overview in the browser if there is no index.html in the current folder.

cd _site
python3 -m http.server 4000

You can even run this from the project root to view your source files as folder. but anything not html such as markdown will be viewed as plain text or get prompted to download it to Downloads

In terms of standard Jekyll serve to view a site…

If you want to iterate over a directory to build up a visitor facing menu or table of contents you can iterate over

{{ site.pages }}

And use the page.title or page.path etc.

And it can be filtered to just the current subdirectory.

Is there also a solution that works on Github Pages?

Using the {{ site.pages }} method and applying a filter would also mean I’d have to manually create a file for each directory.

A page knows its own path

{{ page.path }}

so you just filter dynamically to pages which are in the same directory (or below) for the current page. This can be done once as a layout and reused

My plan is to use this to have a project with multiple nested levels but the at each level uses a common layout and shows the table of contents for the directory

Yes, I know that. But if I access the pages in the directory using Liquid, I still have to create a file for each directory manually. My question is if there is an option to make Jekyll generate such an overview automatically, or enable the browser built-in directory view on GitHub pages.

directory browsing/listing as I have seen it is a function of the webserver - what you want in your 1st post is what I usually see happen when running jekyll serve - if you pull up a directory only (no index.html file) I usually see a list of files - but I have all my files output at index.html inside a folder with the title - so some-file.html would not exist - it would be some-file/index.html.

If in the browser I put /some-directory/ I would get a file list (haven’t done this in a long time so could be wrong now) as there would be no index file there and the built in webserver for jekyll I think does have enable directory listing turned on. But that is just locally. My understanding is that this is a really bad practice to have this enabled for public websites as it would show anything and everything which could show all kinds of files with secret keys and what not.

So if you want this locally, I think it is possible and may have to do with the permalink structure if it is not working for you.

If you want this on GH then I don’t think it is going to happen without you somehow creating it which I can’t see an easy way to do.

Ahh, hm that makes sense. Than you for your answer!

Great. I didn’t know about that feature

The Python server option will I mentioned above will do the same thing for a directory, just lacking the Jekyll server features.

Its jekyll serve --show-dir-listing and it works for me. It ignores an index file is there is one.

The flag is needed to replace index.html but otherwise you can omit the flag and see the directory listing. I just tested

It turns out no change was needed and the functionality was builtin all along.