summaryrefslogtreecommitdiff
path: root/build-member.sh
blob: d171dbb8dcca9f16a7301053fc82674d7dad0932 (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
90
91
92
#!/bin/bash

set -eu

input=$1
template=$2
outdir=$3
uri=$4
output="${outdir}/${uri}"

. settings.sh

firstname ()
{
    local -r fullname=$1
    local name=${fullname%% *}
    echo ${name,}
}

generate-parameters ()
{
    read fullname
    local -r firstname=$(firstname "${fullname}")

    cat <<EOF
title='${fullname}'
stylesheets=(membre)
transforms=("\$(transform-li-dropdown-current-a quatuor)"
            "\$(transform-li-current-a quatuor)"
            "\$(transform-li-current-a ${firstname})")
translation=${firstname}
EOF
}

pandoc-inline ()
{
    ${pandoc} | sed -r 's,^<p>(.+)</p>$,\1,'
}

generate-main ()
{
    read fullname
    read instrument
    read emph1
    read emph2
    local -r name=$(firstname "${fullname}")

    cat <<EOF
<main style="--emph1-color: ${emph1}; --emph2-color: ${emph2}">
  <div class="bio-title">
    <h1 class="name">${fullname}</h1>
    <h2 class="instrument">${instrument}</h2>
  </div>
  <div class="bio">
EOF

    while read line
    do
        # Ignore empty lines.
        if [[ ${line} =~ ^[[:space:]]*$ ]]
        then
            continue
        fi

        # Pasting from GDoc yields trailing spaces; remove those.
        if ! [[ ${line} =~ ([^?]+\?)\ (.+[^ ])\ * ]]
        then
            >&2 echo "Invalid line: ${line}"
            continue
        fi

        cat <<EOF
    <dl>
      <dt>$(pandoc-inline <<< "${BASH_REMATCH[1]}") </dt>
      <dd>$(pandoc-inline <<< ${BASH_REMATCH[2]})</dd>
    </dl>
EOF
    done

    imgdir=$(realpath --relative-to $(dirname "${template}") images)

    cat <<EOF
  </div>
  <img src="${imgdir}/${name}/portrait.png" style="background-image: url(${imgdir}/${name}/bg.jpg)">
</main>
EOF
}

./build.sh <(generate-main < "${input}")        \
           <(generate-parameters < "${input}")  \
           "${template}"                        \
           "${outdir}" "${uri}"