Notebook.sh: Difference between revisions
No edit summary |
No edit summary |
||
Line 19: | Line 19: | ||
WIKIPAGE=$1 | WIKIPAGE=$1 | ||
# | # Feature: local CSS edits first! | ||
# --------------------------------------------------------------- | # --------------------------------------------------------------- | ||
# The script will only download a local "booklet-stylesheet.css" | # The script will only download a local "booklet-stylesheet.css" | ||
# if you don't have this file on your computer yet; | # if you don't have this file on your computer yet; | ||
# In other words: it never overwrites your local | # In other words: it never overwrites your local edits. | ||
# This allows for making custom modifications to the stylesheet | # This allows for making custom modifications to the stylesheet | ||
# for a specific booklet. :) | # for a specific booklet. :) |
Revision as of 22:06, 26 November 2023
The Exploratory Programming textbook written by Nick Monfort suggests to get paper in the room when learning to do programming, which was a trigger to start producing printed booklets for the prototyping classes.
This year, I'm curious to explore ways to generate these booklets from the wiki, and hook into one of the habits and rhythms at the course that is quite central: wiki editing.
Publishing the code and stylesheet (as executable CSS) on the wiki, as a hook into these habits, lets code resonate with the wiki environment, approaching code as a document and not "just" a script.
The script below uses curl
, pandoc
, weasyprint
, pdfbook2
and Booklet-stylesheet.css as a stylesheet to render a PDF from a wiki page.
You can copy the script and save it as a local bash file, for example: booklet.sh
.
And run it with: $ bash booklet.sh WIKIPAGE
, for example: $ bash booklet.sh Pen_plotters
Note that you should use underscores and not spaces in the wiki pagename!
#!/bin/bash
# insert your wiki page below, between the quotes
WIKIPAGE=$1
# Feature: local CSS edits first!
# ---------------------------------------------------------------
# The script will only download a local "booklet-stylesheet.css"
# if you don't have this file on your computer yet;
# In other words: it never overwrites your local edits.
# This allows for making custom modifications to the stylesheet
# for a specific booklet. :)
if [[ $(ls booklet-stylesheet.css) ]]; then
echo ">>> local booklet-sylesheet.css found"
else
echo ">>> downloading booklet-sylesheet.css"
curl --silent https://pzwiki.wdka.nl/mediadesign/User:Manetta/Booklet-stylesheet.css?action=raw > booklet-stylesheet.css
fi
curl --silent https://pzwiki.wdka.nl/mediadesign/User:Manetta/Booklet-stylesheet.css?action=raw > booklet-stylesheet.css.tmp
DIFF=$(diff booklet-stylesheet.css.tmp booklet-stylesheet.css)
if [[ $DIFF ]]; then
echo ">>> checking booklet-sylesheet.css: local edits were made"
else
echo ">>> checking booklet-sylesheet.css: in sync with User:Manetta/Booklet-stylesheet.css"
fi
rm booklet-stylesheet.css.tmp
# Turn the HTML page into a PDF with weasyprint
# ---------------------------------------------------------------
echo ">>> generating $WIKIPAGE.pdf (with weasyprint)"
weasyprint https://pzwiki.wdka.nl/mediadesign/$WIKIPAGE?action=render --stylesheet booklet-stylesheet.css $WIKIPAGE.pdf
# And turn the PDF into an A5 booklet PDF for printing
# ---------------------------------------------------------------
# pdfbook2 is part of the texlive-extra-utils package in Debian
echo ">>> generating $WIKIPAGE-book.pdf (with pdfbook2)"
pdfbook2 --paper=a4paper --short-edge --no-crop $WIKIPAGE.pdf