Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
blob: 0f12a2ec5dc2e98812b99d49c09158c927b23c25 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# Generate talks HTML page
#
#  Copyright (C) 2019 Mike Gerwitz
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Talks are organized along with abstract in $TALKFILE.  Abstracts are
# assumed to be Markdown-formatted and are run through Pandoc.  A link to
# the talk video is provided, along with any supplemental links provided via
# $TALKFILE (e.g. slides, source code, bibliography).
##

set -euo pipefail

# Recfile containing talk abstracts and metadata.
declare -r TALKFILE=${TALKFILE:-src/talks.rec}


# List ids of all talks in $TALKFILE.
talk-list()
{
  recsel -CP id "$TALKFILE"
}


# Retrieve field FIELD from talk identified by ID in $TALKFILE.
talk-field()
{
  local -r id=${1?Missing talk id}
  local -r field=${2?Missing talk field}

  local result status
  result=$( recsel -P "$field" -e "id = '$id'" "$TALKFILE" )
  status=$?

  [ $? -a -n "$result" ] && echo "$result"
}


# Produce string to handle past or future dates.
present-relative()
{
  local -r date=${1?Missing date}

  local -i now udate
  now=$(date +%s)
  udate=$( date --date="$date" +%s )

  if [ "$now" -lt "$udate" ]; then
    echo 'Will be presented'
  else
    echo Presented
  fi
}


# Generate abstract for talk.
abstract()
{
  local -r id=${1?Missing talk id}

  local title location locimg date abstract url links
  title=$( talk-field "$id" title )
  location=$( talk-field "$id" location )
  locimg=$( talk-field "$id" locimg )
  date=$( talk-field "$id" date )
  abstract=$( talk-field "$id" abstract )
  url=$( talk-field "$id" video_url || echo "#$id" )
  event_link=$( talk-field "$id" event_link )
  links=$( talk-field "$id" link || true )

  local abstract_html
  abstract_html=$( pandoc -fmarkdown -thtml5 <<< "$abstract" )

  local watch_title=
  if [[ ! "$url" =~ ^# ]]; then
    watch_title="Watch $location Talk"
  fi

  present=$( present-relative "$date" )

  cat <<EOF
<article class="abstract talk">
  <h2 class="title" id="$id">$title</h2>

  <ul class="links">
    <li><a class="video $locimg" href="$url">$watch_title</a></li>
    $(
      while read lurl ltitle; do
        printf "<li><a href="%s">%s</a></li>\n" "$lurl" "$ltitle"
      done <<< "$links"
    )
  </ul>

  $abstract_html

  <p class="date">$present on $date at
    <a href="$event_link">$location</a>.</p>
</article>
EOF
}


# Generate talks page.
main()
{
  src/mkheader talks Talks

  local talks
  talks=$( recsel -P id src/talks.rec )

  echo '<h1>Talks</h1>'
  talk-list | while read id; do abstract "$id"; done

  cat src/footer.tpl.htm
}


main "$@"