Background
Remember those classic directory listings from the early days of the web? They're still useful today, especially for some static sites hosted on GitHub Pages.
In this quick tutorial,I'll show you how to automatically create static directory listings on GitHub Actions/Pages with a simple PHP script I created a while back.
Best parts: It's totally free, has no dependencies, and works perfectly in GitHub Actions as they have a built-in PHP runtime.
Screenshot
Here's a screenshot of the directory listing created by the script:
Trying it locally
To get started, you can try the script locally. Here's how:
Download the script from the GitHub repository:
1wget https://raw.githubusercontent.com/caendesilva/php-directory-listing/master/directory-listing.php -O directory-listing.php
Next run the script in your terminal:
1php directory-listing.php
This will create a self-contained index.html
file with a directory listing of the current directory.
Using it in GitHub Actions
To use the script in GitHub Actions, you can base it on this sample workflow:
1# GitHub Actions demo to create a directory listing for the repository files to publish to GitHub Pages 2 3name: Demo Action 4 5on: 6 push: 7 branches: [ "main" ] 8 9permissions:10 contents: read11 pages: write12 id-token: write13 14jobs:15 build:16 runs-on: ubuntu-latest17 18 steps:19 - uses: actions/checkout@v320 21 # Download the directory listing script22 - name: Download Directory Listing Script23 run: wget https://raw.githubusercontent.com/caendesilva/php-directory-listing/master/directory-listing.php -O directory-listing.php24 25 # Run the directory listing script26 - name: Run Directory Listing Script27 run: php directory-listing.php28 29 # Optional: Deploy to GitHub Pages (you can also commit the file to your repository)30 - name: Setup Pages31 uses: actions/configure-pages@v532 - name: Upload artifact33 uses: actions/upload-pages-artifact@v334 with:35 path: '.'36 - name: Deploy to GitHub Pages37 id: deployment38 uses: actions/deploy-pages@v4
This workflow will create a directory listing of the repository files and publish it to GitHub Pages.
Conclusion
That's it! You now have a simple way to create static directory listings on GitHub Actions/Pages. Feel free to customize the script or workflow to fit your needs.
See the source code at https://github.com/caendesilva/php-directory-listing and try the live demo at https://git.desilva.se/php-directory-listing/.
Syntax highlighting by Torchlight.dev