thoughts/src/talks.sh

102 lines
2.5 KiB
Bash
Executable File

#!/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}
recsel -P "$field" -e "id = '$id'" "$TALKFILE"
}
# 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 )
links=$( talk-field "$id" link )
local abstract_html
abstract_html=$( pandoc -fmarkdown -thtml5 <<< "$abstract" )
cat <<EOF
<article class="abstract talk">
<h2 class="title" id="$id">$title</h2>
<ul class="links">
<li><a class="video $locimg" href="$url">Watch $location Talk</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">Presented on $date.</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 "$@"