From 017713a06309177d64062f224e214edcd9c0f64b Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 9 Nov 2021 00:43:58 +0000 Subject: [PATCH] refactor: replace workspace.yml with `run` --- run | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ workspace.yml | 46 ------------------------------------------ 2 files changed, 56 insertions(+), 46 deletions(-) create mode 100755 run delete mode 100644 workspace.yml diff --git a/run b/run new file mode 100755 index 0000000..82a3506 --- /dev/null +++ b/run @@ -0,0 +1,56 @@ +#!/bin/bash + +set -e + +PDF_FILENAME=slides.pdf +RST_FILENAME=slides.rst +THUMBNAIL_FILENAME=thumbnail.jpg + +function clean:all { + # Clean all generated files. + + find . \ + -type f \( -name "${PDF_FILENAME}*" -o -name *.build_temp -o -name ${THUMBNAIL_FILENAME} \) \ + -delete +} + +function help { + printf "%s [args]\n\nTasks:\n" "${0}" + + compgen -A function | grep -v "^_" | cat -n + + printf "\nExtended help:\n Each task has comments for general usage\n" +} + +function pdf:generate { + # Generate a new PDF file. + + DIRECTORY_NAME=$1 + shift 1 + + docker run --rm -it \ + -v $HOME/.local/share/fonts:/usr/share/fonts \ + -v $PWD/${DIRECTORY_NAME}:/rst2pdf \ + -w /rst2pdf \ + opdavies/rst2pdf \ + ${RST_FILENAME} \ + --break-level 1 \ + --extension-module preprocess \ + --fit-background-mode scale \ + --font-path /usr/share/fonts \ + --output ${PDF_FILENAME} \ + --stylesheets main,tango \ + "${@}" +} + +function pdf:watch { + # Generate a new PDF file and watch for changes. + echo "TODO: pdf:watch" +} + +function thumbnail:generate { + # Generate a thumbnail image of the first slide in the presentation. + echo "TODO: thumbnail:generate" +} + +eval "${@:-help}" diff --git a/workspace.yml b/workspace.yml deleted file mode 100644 index 273a43f..0000000 --- a/workspace.yml +++ /dev/null @@ -1,46 +0,0 @@ -workspace('talks'): - description: 'My slide decks' - -attributes: - rst2pdf: - command: | - = 'docker run --rm -it -v $PWD:/rst2pdf -v $HOME/.local/share/fonts:/usr/share/fonts -w /rst2pdf opdavies/rst2pdf ' ~ @('rst2pdf.filename.rst') ~ ' - --break-level 1 - --stylesheets main,tango - --fit-background-mode scale - --extension-module preprocess - --output ' ~ @('rst2pdf.filename.pdf') ~ ' - --font-path /usr/share/fonts' - filename: - pdf: slides.pdf - rst: slides.rst - thumbnail: - filename: thumbnail.png - -command('clean all'): - env: - PDF_FILENAME: = @('rst2pdf.filename.pdf') - RST_FILENAME: = @('rst2pdf.filename.rst') - THUMBNAIL_FILENAME: = @('thumbnail.filename') - exec: | - #!bash - run "find . -type f \( -name '$PDF_FILENAME*' -o -name *.build_temp -o -name $THUMBNAIL_FILENAME \) -delete" - -command('pdf generate '): | - #!bash|= - cd ={ input.argument('talk') } - passthru ={ @('rst2pdf.command') } - -command('pdf watch '): | - #!bash|= - cd ={ input.argument('talk') } - passthru nodemon -e rst,style,txt,jpg,png -x "={ @('rst2pdf.command') }" - -command('thumbnail '): - env: - PDF_FILENAME: = @('rst2pdf.filename.pdf') - THUMBNAIL_FILENAME: = @('thumbnail.filename') - exec: | - #!bash|= - cd ={ input.argument('talk') } - passthru gs -sDEVICE=png16m -r300 -dDownScaleFactor=4 -sOutputFile=$THUMBNAIL_FILENAME -dLastPage=1 $PDF_FILENAME