talks/run

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env bash
2024-01-25 15:49:02 +00:00
set -o errexit
set -o nounset
set -o pipefail
PDF_FILENAME=slides.pdf
2024-01-25 15:49:02 +00:00
RST_FILENAME="${RST_FILENAME:-slides.rst}"
THUMBNAIL_FILENAME=thumbnail.jpg
function clean {
rm -fr dist/*
2023-10-17 08:36:46 +00:00
touch dist/.keep
find . \
-type f \( -name "${PDF_FILENAME}*" -o -name *.build_temp -o -name ${THUMBNAIL_FILENAME} \) \
-delete
}
2024-01-25 15:49:02 +00:00
function generate {
generate:pdf "${@}"
}
2024-01-25 15:49:02 +00:00
function generate:pdf {
2023-11-01 21:38:55 +00:00
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
DIRECTORY_NAME=$1
shift 1
pushd "src/${DIRECTORY_NAME}"
rst2pdf "${RST_FILENAME}" \
--break-level 1 \
-e preprocess \
--fit-background-mode scale \
--font-path ../fonts \
--output "../../dist/${DIRECTORY_NAME}.pdf" \
2024-08-09 20:12:54 +00:00
--stylesheets ../styles/opdavies-light,tango \
"${@}"
popd
2024-01-25 15:49:02 +00:00
tree dist
}
# Generate JPG thumbnails of each slide in a presentation.
2024-01-25 15:49:02 +00:00
function generate:thumbnail {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
if [ ! -d "src/${1}" ]; then
echo "${1} not found"
exit 2
fi
2024-01-25 15:49:02 +00:00
generate:pdf "${1}"
mkdir -p "dist/${1}"
gs \
-dBATCH \
-dDownScaleFactor=3 \
-dNOPAUSE \
-r600 \
-sDEVICE=jpeg \
-sOutputFile="dist/${1}/%d.jpg" \
"dist/${1}.pdf"
}
2024-01-25 15:49:02 +00:00
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# Create a new talk.
function new {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
if [[ -e "src/${1}" ]]; then
echo "Error: ${1} already exists."
exit 1
fi
mkdir -vp "src/${1}"
touch "src/${1}/slides.rst"
}
function present {
TALK_PATH=$1
shift 1
pdfpc "${@}" "dist/${TALK_PATH}.pdf"
}
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"