diff options
| author | Johannes Herman <johannes.herman@gmail.com> | 2025-12-11 06:49:19 +0100 |
|---|---|---|
| committer | Johannes Herman <johannes.herman@gmail.com> | 2025-12-11 06:49:19 +0100 |
| commit | c14aabfd17c85632bd68db60867edb3fb662c7e7 (patch) | |
| tree | d3fc7a1c44bba6fa56c39bd77013911151977532 /bin/make_html_table.sh | |
initial commit
Diffstat (limited to 'bin/make_html_table.sh')
| -rwxr-xr-x | bin/make_html_table.sh | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/bin/make_html_table.sh b/bin/make_html_table.sh new file mode 100755 index 0000000..c820f27 --- /dev/null +++ b/bin/make_html_table.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +CSV_FILE="${1:-tricks.csv}" + +make_video_cell() { + local field="$1" + if [[ -n "$field" ]]; then + echo " <td>" + IFS=';' read -ra files <<< "$field" + for f in "${files[@]}"; do + f_trimmed=$(echo "$f" | xargs) + echo " <video width=\"256\" controls preload=\"none\" poster=\"thumbnails/$f_trimmed.jpg\">" + echo " <source src=\"videos/$f_trimmed.mp4\" type=\"video/mp4\">" + echo " Your browser does not support the video tag." + echo " </video>" + done + echo " </td>" + else + echo " <td></td>" + fi +} + +make_demo_cell() { + local field="$1" + if [[ -n "$field" ]]; then + echo " <td>" + IFS=';' read -ra files <<< "$field" + for f in "${files[@]}"; do + f_trimmed=$(echo "$f" | xargs) + echo " <a href=\"demos/$f_trimmed\" download>demo</a><br>" + done + echo " </td>" + else + echo " <td></td>" + fi +} + +make_montage_cell() { + local montage="$1" + + if [ -z "$montage" ]; then + echo " <td></td>" + return + fi + + case "$montage" in + 'Cowboy Teebop') montage_url='https://www.youtube.com/watch?v=eJgiPbio9BY' ;; + 'Tee Jams') montage_url='https://www.youtube.com/watch?v=ReoM0rVXduQ' ;; + 'On Noby Street') montage_url='https://www.youtube.com/watch?v=lxVu5XX9Rmk' ;; + 'Any Trickers') montage_url='https://www.youtube.com/watch?v=u2CbuvmiXCc' ;; + *) echo "ERROR: invalid montage name '$montage'" >&2; exit 1 ;; + esac + echo " <td><a href=\"$montage_url\" target=\"_blank\" rel=\"noopener\">$montage</a></td>" +} + +cat <<'EOF' +<table> + <tr> +EOF + +IFS=',' read -r -a headers < "$CSV_FILE" + +for header in "${headers[@]}"; do + echo " <th><strong>$header</strong></th>" +done + +echo " </tr>" + +while IFS=',' read -r name players train_videos ingame_videos demos montage; do + [[ -z "$name" ]] && continue + + echo " <tr>" + echo " <td><strong>$name</strong></td>" + + players_html=$(echo "$players" | sed 's/;/,<br>/g') + echo " <td>$players_html</td>" + + make_video_cell "$train_videos" + make_video_cell "$ingame_videos" + make_demo_cell "$demos" + make_montage_cell "$montage" + + echo " </tr>" +done < <(tail -n +2 "$CSV_FILE") + +cat <<'EOF' +</table> +EOF + |
