Notebook.sh: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The [https://nickm.com/ep2e/ 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.  
The [https://nickm.com/ep2e/ 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 notebooks 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. There is a lot to find on this wiki, some pages date from years back, which can easily turn a moment of wiki editing into discovery moments of "who wrote this?" and "oh, did this happen?".
This year, I'm curious to explore ways to generate these notebooks 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 hooks into this, letting code resonate with the wiki environment, approaching code as a document and not "just" a script.  
Publishing the code and stylesheet (as executable CSS) on the wiki hooks into these habits. As a form of [https://en.wikipedia.org/wiki/Literate_programming literate programming], it lets code resonate with the wiki environment while storing code as a document and not "just" a script.  


The script below uses <code>curl</code>, <code>pandoc</code>, <code>weasyprint</code>, <code>pdfbook2</code> and [[User:Manetta/Booklet-stylesheet.css|Booklet-stylesheet.css]] as a stylesheet to render a PDF from a wiki page.
The script below uses <code>curl</code>, <code>pandoc</code>, <code>weasyprint</code>, <code>pdfbook2</code> and [[Notebook-stylesheet.css|Notebook-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: <code>booklet.sh</code>.
You can copy the script and save it as a local bash file, for example: <code>notebook.sh</code>.


And run it with: <code>$ bash booklet.sh WIKIPAGE</code>, for example: <code>$ bash booklet.sh Pen_plotters</code>
And run it with: <code>$ bash notebook.sh WIKIPAGE</code>, for example: <code>$ bash notebook.sh Pen_plotters</code>


Note that you should use '''underscores''' and not '''spaces''' in the wiki pagename!
Note that you should use '''underscores''' and '''not spaces''' in the wiki pagename!


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
#!/bin/bash
#!/bin/bash


# insert your wiki page below, between the quotes
# Capturing the wiki page
# ---------------------------------------------------------------
# the wiki page that you wrote as an argument in the command line,  
# is stored in this variable
WIKIPAGE=$1
WIKIPAGE=$1
echo ">>> making a notebook from the wiki page: $WIKIPAGE"


# Extra feature: local CSS edits first!
# Feature: local CSS edits first!
# ---------------------------------------------------------------
# ---------------------------------------------------------------
# The script will only download a local "booklet-stylesheet.css"
# The script will only download a local "notebook-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 stylesheet!
# 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 notebook. :)
if [[ $(ls booklet-stylesheet.css) ]]; then
if [[ $(ls notebook-stylesheet.css) ]]; then
         echo ">>> local booklet-sylesheet.css found"
         echo ">>> local notebook-sylesheet.css found"
else
else
         echo ">>> downloading booklet-sylesheet.css"
         echo ">>> downloading notebook-sylesheet.css"
         curl --silent  https://pzwiki.wdka.nl/mediadesign/User:Manetta/Booklet-stylesheet.css?action=raw > booklet-stylesheet.css
         curl --silent  https://pzwiki.wdka.nl/mediadesign/Notebook-stylesheet.css?action=raw > notebook-stylesheet.css
fi
fi


curl --silent  https://pzwiki.wdka.nl/mediadesign/User:Manetta/Booklet-stylesheet.css?action=raw > booklet-stylesheet.css.tmp
curl --silent  https://pzwiki.wdka.nl/mediadesign/Notebook-stylesheet.css?action=raw > notebook-stylesheet.css.tmp


DIFF=$(diff booklet-stylesheet.css.tmp booklet-stylesheet.css)
DIFF=$(diff notebook-stylesheet.css.tmp notebook-stylesheet.css)
if [[ $DIFF ]]; then
if [[ $DIFF ]]; then
         echo ">>> checking booklet-sylesheet.css: local edits were made"
         echo ">>> checking notebook-sylesheet.css: local edits were made"
else
else
         echo ">>> checking booklet-sylesheet.css: in sync with User:Manetta/Booklet-stylesheet.css"
         echo ">>> checking notebook-sylesheet.css: in sync with the wiki page Notebook-stylesheet.css"
fi
fi


rm booklet-stylesheet.css.tmp
rm notebook-stylesheet.css.tmp


# Turn the HTML page into a PDF with weasyprint
# Turn the HTML page into a PDF with weasyprint
# ---------------------------------------------------------------
# ---------------------------------------------------------------
echo ">>> generating $WIKIPAGE.pdf (with weasyprint)"
PDFNAME=$(echo "$WIKIPAGE" | tr :/#%{}\&\\\<\>*?/\!\'\"@+\`= _)
weasyprint https://pzwiki.wdka.nl/mediadesign/$WIKIPAGE?action=render --stylesheet booklet-stylesheet.css $WIKIPAGE.pdf
echo ">>> generating $PDFNAME.pdf (with weasyprint)"
weasyprint https://pzwiki.wdka.nl/mediadesign/$WIKIPAGE?action=render --stylesheet notebook-stylesheet.css $PDFNAME.pdf


# And turn the PDF into an A5 booklet PDF for printing
# And turn the PDF into an A5 booklet PDF for printing
# ---------------------------------------------------------------
# ---------------------------------------------------------------
# pdfbook2 is part of the texlive-extra-utils package in Debian
# pdfbook2 is part of the texlive-extra-utils package in Debian
echo ">>> generating $WIKIPAGE-book.pdf (with pdfbook2)"
echo ">>> generating $PDFNAME-book.pdf (with pdfbook2)"
pdfbook2 --paper=a4paper --short-edge --no-crop $WIKIPAGE.pdf
pdfbook2 --paper=a4paper --short-edge --no-crop $PDFNAME.pdf
 
 
</syntaxhighlight>
</syntaxhighlight>
This script is used to make:
* https://git.xpub.nl/XPUB/pen-plotter-zine
* ...

Latest revision as of 13:34, 9 September 2024

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 notebooks for the prototyping classes.

This year, I'm curious to explore ways to generate these notebooks 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 hooks into these habits. As a form of literate programming, it lets code resonate with the wiki environment while storing code as a document and not "just" a script.

The script below uses curl, pandoc, weasyprint, pdfbook2 and Notebook-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: notebook.sh.

And run it with: $ bash notebook.sh WIKIPAGE, for example: $ bash notebook.sh Pen_plotters

Note that you should use underscores and not spaces in the wiki pagename!

#!/bin/bash

# Capturing the wiki page
# ---------------------------------------------------------------
# the wiki page that you wrote as an argument in the command line, 
# is stored in this variable
WIKIPAGE=$1
echo ">>> making a notebook from the wiki page: $WIKIPAGE"

# Feature: local CSS edits first!
# ---------------------------------------------------------------
# The script will only download a local "notebook-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 notebook. :)
if [[ $(ls notebook-stylesheet.css) ]]; then
        echo ">>> local notebook-sylesheet.css found"
else
        echo ">>> downloading notebook-sylesheet.css"
        curl --silent  https://pzwiki.wdka.nl/mediadesign/Notebook-stylesheet.css?action=raw > notebook-stylesheet.css
fi

curl --silent  https://pzwiki.wdka.nl/mediadesign/Notebook-stylesheet.css?action=raw > notebook-stylesheet.css.tmp

DIFF=$(diff notebook-stylesheet.css.tmp notebook-stylesheet.css)
if [[ $DIFF ]]; then
        echo ">>> checking notebook-sylesheet.css: local edits were made"
else
        echo ">>> checking notebook-sylesheet.css: in sync with the wiki page Notebook-stylesheet.css"
fi

rm notebook-stylesheet.css.tmp

# Turn the HTML page into a PDF with weasyprint
# ---------------------------------------------------------------
PDFNAME=$(echo "$WIKIPAGE" | tr :/#%{}\&\\\<\>*?/\!\'\"@+\`= _)
echo ">>> generating $PDFNAME.pdf (with weasyprint)"
weasyprint https://pzwiki.wdka.nl/mediadesign/$WIKIPAGE?action=render --stylesheet notebook-stylesheet.css $PDFNAME.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 $PDFNAME-book.pdf (with pdfbook2)"
pdfbook2 --paper=a4paper --short-edge --no-crop $PDFNAME.pdf

This script is used to make: