How to allow directory listing on gitlab.com pages?

I’d like to allow listing of directory/files structure for my static content at gitlab.com pages. I have commited file .htaccess with Options +Indexes content, but it doesn’t help. For all subdirectories gitlab.io returns 404 status page instead of nice listing.
Is it possible to set access rules to the directory tree through .htaccess or by another method?

2 Likes

Did you ever find a solution for this? I would love to do the same thing.

Nope. I’ve solved my problem by dumping filesystem structure to the file in deploy phase like this:

image: alpine:latest
pages:
  stage: deploy
  script:
  - cd public/
  - find -print > ../.tree
  - mv ../.tree .
  artifacts:
    paths:
    - public/
  only:
  - master

Yeah I ended up using a similar solution. I’m building my public directory from another repository, so I actually have a deploy script that uses tree to create an html file (among other things) and pushes the changes up. I think your solution is a bit more elegant though.

1 Like

Care to share that ?

Sure thing. The repo is here:

This is only used by me, so it’s not the most descriptive. I also used R, which is my favorite language, though something else might have been more sensible. Let me know if you’d like me to clarify anything.

2 Likes

Our server didn’t have the tree command. After a few tries, I ended up with this script to make a simplistic html of the directory listing> :

image: alpine:latest
pages:
  tags:
  - pages
  stage: deploy
  script:
  - cd public/
  - echo "<html><body><h1>Directory listing:</h1>" > ./index.html
  - find -exec echo "<a href='{}'>{}</a><br/>" \; >> ./index.html
  - echo "</body></html>" >> ./index.html
  artifacts:
    paths:
    - public
  only:
  - master
2 Likes

Forgot to post the result here - I was looking into a tree listing for a monitoring webcast, which published coverage reports. This is the solution I came up with in the end: .gitlab-ci.yml · main · Developer Evangelism at GitLab / workshops / Identify analyze action - Deep monitoring with CI · GitLab

pages:
  stage: report
  needs: ["test-coverage-report"]
  before_script:
    - apt-get update && apt-get -y install tree
  script:
    - echo "Deploying coverage reports to pages"
    - tree ./public -H '.' -T "$title" -I "reveal*|img*|style*|index*|content*" --noreport --charset utf-8 > ./public/index.html
  artifacts:
    paths:
    - public

It uses the golang:latest image for earlier build steps in the CI config.

1 Like

you can get better results and auto create index.html on every sub directory with apindex guangrei / apindex · GitLab