summaryrefslogtreecommitdiff
path: root/bin/make_html_table.sh
blob: c820f279240699965667fbf218c387afc4749565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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