Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set -e
- $OUT = "index.html"
- $DIR = "${1:-.}"
- $RECURSIVE = "0"
- # Optional flags
- foreach ($arg in ""$@"") {
- case "$arg" in
- --recursive|-r) RECURSIVE=1 ;;
- esac
- }
- $DIR = "$(realpath "$DIR")"
- Write-Host "[*] Building index for: $DIR"
- # HTML header
- cat > "$OUT" <<EOF
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Index of $(basename "$DIR")</title>
- <style>
- body { background:#0e0e0e; color:#e0e0e0; font-family:monospace; }
- a { color:#6cf; text-decoration:none; }
- .grid { display:flex; flex-wrap:wrap; gap:10px; }
- .item { width:200px; border:1px solid #333; padding:5px; }
- img { max-width:100%; height:auto; }
- </style>
- </head>
- <body>
- <h2>Index of $(basename "$DIR")</h2>
- <div class="grid">
- EOF
- # File listing
- if ([bool]$"$RECURSIVE" -eq 1) {
- $FILES = "$(find "$DIR" -type f)"
- else {
- $FILES = "$(find "$DIR" -maxdepth 1 -type f)"
- }
- while IFS= read -r file; do
- $rel = "${file#$DIR/}"
- $ext = "${file##*.}"
- $ext = "$(echo "$ext" | tr '[:upper:]' '[:lower:]')"
- Write-Host "<div class='item'>" >> "$OUT"
- case "$ext" in
- jpg|jpeg|png|gif|webp)
- Write-Host "<a href=\"$rel\"><img src=\"$rel\"></a><br>$rel" >> "$OUT"
- ;;
- mp4|mkv|webm)
- Write-Host "<video src=\"$rel\" controls width=180></video><br>$rel" >> "$OUT"
- ;;
- mp3|wav|ogg)
- Write-Host "<audio src=\"$rel\" controls></audio><br>$rel" >> "$OUT"
- ;;
- *)
- Write-Host "<a href=\"$rel\">$rel</a>" >> "$OUT"
- ;;
- esac
- Write-Host "</div>" >> "$OUT"
- done <<< "$FILES"
- # Footer
- cat >> "$OUT" <<EOF
- </div>
- </body>
- </html>
- EOF
- Write-Host "[✓] Created $OUT"
Advertisement
Add Comment
Please, Sign In to add comment