diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c77e2e1..ebc3c81 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -29,42 +29,132 @@ jobs: - name: Configure Pages uses: actions/configure-pages@v5 - - name: Aggregate files from all branches into ./public + - name: Aggregate and build recursive directory pages shell: bash run: | set -euo pipefail + + OWNER="${GITHUB_REPOSITORY%/*}" + REPO="${GITHUB_REPOSITORY#*/}" + SITE_ROOT="/${REPO}/" + mkdir -p public + : > public/.nojekyll - # List remote branches (exclude HEAD pointer) - mapfile -t BRANCHES < <(git ls-remote --heads origin \ - | awk '{print $2}' | sed 's@refs/heads/@@') + # List remote branches + mapfile -t BRANCHES < <( + git ls-remote --heads origin | awk '{print $2}' \ + | sed 's@refs/heads/@@' + ) - # Minimal index page + # Top-level landing page cat > public/index.html <<'HTML' - -
| Name | Size | Modified |
|---|---|---|
| 📁 $d/ | — | — |
| 📄 $f | $size_h | $mod |
Generated $(date -u '+%Y-%m-%d %H:%M UTC')
" + } > "$DIR/index.html" + } + + # Process each branch for BR in "${BRANCHES[@]}"; do - SAFE=$(echo "$BR" | tr '/:@ ' '----' | sed 's/[^A-Za-z0-9._-]/-/g') + SAFE="$(echo "$BR" | tr '/:@ ' '----' | sed 's/[^A-Za-z0-9._-]/-/g')" mkdir -p "public/$SAFE" - # Fetch that branch tip and export without checkout + # Fetch and extract content without checkout git fetch --depth=1 origin "$BR" git archive --format=tar FETCH_HEAD | tar -x -C "public/$SAFE" - # Keep only static assets; drop heavy/unneeded dirs + # Keep only static assets, then remove empty dirs rm -rf "public/$SAFE/.git" "public/$SAFE/.github" "public/$SAFE/node_modules" find "public/$SAFE" -type f ! \ \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.json' -o \ - -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o -name '*.svg' \) \ - -delete + -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o \ + -name '*.svg' \) -delete find "public/$SAFE" -type d -empty -delete - echo "