Skip to content

Commit

Permalink
Include subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
korenmiklos authored Jan 18, 2024
1 parent fe20455 commit ded1d21
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/index.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update Index HTML for All Folders
name: Update Index HTML with Subfolders

on:
push:
Expand All @@ -15,12 +15,17 @@ jobs:
run: |
find . -type d -not -path '*/\.*' | while read -r dir; do
if [ "$(ls -A "$dir")" ]; then
echo "<html><body><ul>" > "$dir/index.html"
echo "<html><body><h2>Index of ${dir#./}</h2><ul>" > "$dir/index.html"
for file in "$dir"/*; do
[ -e "$file" ] || continue
[ -f "$file" ] || continue
file_name=$(basename "$file")
echo "<li><a href='${file_name}'>${file_name}</a></li>" >> "$dir/index.html"
if [ -d "$file" ]; then
# For directories, link to their index.html
echo "<li><a href='${file_name}/index.html'>${file_name}/</a></li>" >> "$dir/index.html"
else
# For files, link directly
echo "<li><a href='${file_name}'>${file_name}</a></li>" >> "$dir/index.html"
fi
done
echo "</ul></body></html>" >> "$dir/index.html"
fi
Expand All @@ -31,5 +36,5 @@ jobs:
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
git add .
git commit -m 'Update index.html files' || exit 0 # Exit gracefully if no changes
git commit -m 'Update index.html files with subfolder links' || exit 0 # Exit gracefully if no changes
git push

0 comments on commit ded1d21

Please sign in to comment.