Skip to content

Utility - remake all index pages #15

Utility - remake all index pages

Utility - remake all index pages #15

name: Utility - remake all index pages
on:
workflow_dispatch:
jobs:
remake-all-indexes:
runs-on: ubuntu-latest
name: Remake file index pages
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Generate index files
run: |
header_html="$(cat template_header.html)"
footer_html="$(cat template_footer.html)"
## MAKE HOME TABLE ##
echo "Working on: home"
table_html=""
table_html+="<table class=\"table table-striped table-bordered table-hover\">"
table_html+="<thead class="table-dark"><tr><th>Folder Name</th><th>File Count</th><th>Last Modified</th></tr></thead>"
table_html+=$'\n'
unique_release_dirs=()
# Loop through all folders in the directory
for subdir in $(find . -mindepth 1 -maxdepth 1 -type d ! -name ".*" | sort -rn)
do
folder=$(basename $subdir)
# Collect unique list of release folders
if [[ ! " ${unique_release_dirs[@]} " =~ " ${folder} " ]]; then
unique_release_dirs+=("$folder")
fi
# Get the count, and last modified date
filecount=$(find $subdir -mindepth 2 -maxdepth 2 -type f ! -name "*.html" | wc -l)
modified=$(git log -1 --format=%cd --date=format:'%d %b %Y %l:%M %p' -- "$subdir")
# Create a table row with the file information
table_html+="<tr><td><a class="file-link" href=\"$folder\">$folder</a></td><td>$filecount</td><td>$modified</td></tr>"
table_html+=$'\n'
done
table_html+="</table>"
# Assemble and save HTML
home_html="$header_html$table_html$footer_html"
echo "$home_html" > "./index.html"
## MAKE RELEASE FOLDER TABLES ##
for release_dir in ${unique_release_dirs[@]}
do
echo "Working on: $release_dir"
table_html=""
table_html+="<table class=\"table table-striped table-bordered table-hover\">"
table_html+="<thead class="table-dark"><tr><th>Folder Name</th><th>File Count</th><th>Last Modified</th></tr></thead>"
table_html+=$'\n'
unique_type_dirs=()
# Loop through all folders in the directory
for subdir in $(find "$release_dir" -mindepth 1 -maxdepth 1 -type d ! -name ".*" | sort)
do
folder=$(basename $subdir)
# Collect unique list of type folders
if [[ ! " ${unique_type_dirs[@]} " =~ " ${folder} " ]]; then
unique_type_dirs+=("$folder")
fi
# Get the count, and last modified date
filecount=$(find $subdir -mindepth 1 -maxdepth 1 -type f ! -name "*.html" | wc -l)
modified=$(git log -1 --format=%cd --date=format:'%d %b %Y %l:%M %p' -- "$subdir")
# Create a table row with the file information
table_html+="<tr><td><a class="file-link" href=\"$folder\">$folder</a></td><td>$filecount</td><td>$modified</td></tr>"
table_html+=$'\n'
done
table_html+="</table>"
# Add parent link (expect top level index)
table_html+='<p><a href="../">Parent directory</a></p>'
# Assemble and save HTML
folder_html="$header_html$table_html$footer_html"
echo "$folder_html" > "$release_dir/index.html"
## MAKE FILE TABLE PER TYPE ##
for dir in ${unique_type_dirs[@]}
do
echo "Working on: $release_dir/$dir"
table_html=""
table_html+="<table class=\"table table-striped table-bordered table-hover\">"
table_html+="<thead class=table-dark><tr><th>File Name</th><th>File Size</th><th>Last Modified</th></tr></thead>"
table_html+=$'\n'
# Loop through all files in the directory
for file in $(find "$release_dir/$dir" -mindepth 1 -maxdepth 1 -type f ! -name "*.html" | sort)
do
if [[ -f "$file" ]]; then
# Get the file name, size, and last modified date
filename=$(basename "$file")
filesize=$(du -h "$file" | cut -f1)
modified=$(git log -1 --format=%cd --date=format:'%d %b %Y %l:%M %p' -- "$file")
# Create a table row with the file information
table_html+="<tr><td><a class="file-link" href=\"$filename\">$filename</a></td><td>$filesize</td><td>$modified</td></tr>"
table_html+=$'\n'
fi
done
table_html+="</table>"
# Add parent link (expect top level index)
table_html+='<p><a href="../">Parent directory</a></p>'
# Assemble and save HTML
file_html="$header_html$table_html$footer_html"
echo "$file_html" > "$release_dir/$dir/index.html"
done
done
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update file index pages
file_pattern: 'index.html **/index.html'