diff --git a/.github/workflows/gh-pages-index.yml b/.github/workflows/gh-pages-index.yml new file mode 100644 index 000000000..7d88a0c1d --- /dev/null +++ b/.github/workflows/gh-pages-index.yml @@ -0,0 +1,65 @@ +name: Generate Directory Indexes + +on: + push: + branches: [gh-pages] + +jobs: + index: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Generate directory indexes + run: | + python3 - <<'EOF' + import os, html + + for dirpath, dirnames, filenames in os.walk('.'): + dirnames[:] = sorted(d for d in dirnames if d != '.git') + entries_files = sorted(f for f in filenames if f != 'index.html') + + rel = os.path.relpath(dirpath, '.') + title = '/' if rel == '.' else '/' + rel + '/' + + lines = [ + '', + f'Index of {html.escape(title)}', + '', + '', + f'

Index of {html.escape(title)}


',
+              ]
+
+              if rel != '.':
+                  lines.append('../')
+
+              for name in dirnames:
+                  lines.append(f'{html.escape(name)}/')
+              for name in entries_files:
+                  lines.append(f'{html.escape(name)}')
+
+              lines += ['

'] + + with open(os.path.join(dirpath, 'index.html'), 'w') as f: + f.write('\n'.join(lines) + '\n') + EOF + + - name: Commit indexes + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -A + if git diff --cached --quiet; then + echo "No index changes" + else + git commit -m "chore: regenerate directory indexes [skip ci]" + git push + fi