Firstly, touch up my blog articles to be suitable for PDF

Do this by automating vim with emacs.

Find blog articles without LATEX_HEADER

1
cd $HOME/blog/posts; find . -name '*.org' | eipct -x -E "! grep -q LATEX_HEADER" | eipct -x grep -q HUGO_BASE | head -n 5
./aws-services.org
./rat.org
./music-playlists-in-emacs-lisp.org
./minor-mode-wrappers-for-shell-commands.org
./review-of-introduction-rust-by-example.org

Automate vim with emacs keyboard macros

I want to add the latex header to all the blog posts without one.

This is the header I’d like to add:

1
2
#+LATEX_HEADER: \usepackage[margin=0.5in]{geometry}
#+OPTIONS: toc:nil

The find script will start vim with the output of a find command.

1
nsfa -E "find . -name \"*.org\" | eipct -x -E \"! grep -q LATEX_HEADER\" | eipct -x grep -q HUGO_BASE | v"

/tmp/nsfa-find-name-org-eipct-x-e-grep-q-latex-hea.sh

Start the find script inside emacs.

This puts vim inside emacs with the results.

1
xa sp -sh

asciinema recording

Create a pdf for every blog post

Make the sort-blog-posts-by-date script

This script scrapes dates from the contents of each blog post using rosie lang and then generates a JSON file using jq, sorted by the date.

The jq input function is used to load lines two at a time into individual json objects.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
export TTY

set -xv

cd /
find $DUMP$NOTES/ws/blog/blog/content/posts -maxdepth 1 -name '*.md' | sed -e 's/.*\/\(.*\)\.md$/\1/' -e "s=^=$HOME/blog/posts/=" -e 's/$/\.org/' | print-line-if-file-exists.sh | awk1 | while IFS=$'\n' read -r line; do
(
    exec 0</dev/null
    echo "$line"
    cat "$line" | sed -n '/^#+DATE:/{p;q}' | rosie-scrape date.dashed
)
done | jq -R "{\"path\": ., \"date\": input}" | jq -c -s "sort_by(.date)[]"

Here is an excerpt:

1
sort-blog-posts-by-date | head -n 5
1
2
3
4
5
{"path":"/home/shane/blog/posts/xenolinguistics.org","date":"2009-02-16"}
{"path":"/home/shane/blog/posts/ruby-operators.org","date":"2009-06-17"}
{"path":"/home/shane/blog/posts/python-data-structures.org","date":"2012-10-12"}
{"path":"/home/shane/blog/posts/use-ssh-key-to-encrypt-messages.org","date":"2015-01-20"}
{"path":"/home/shane/blog/posts/javascript-syntax.org","date":"2016-01-01"}

Make the e-org-latex-export-to-pdf script

This script automates emacs using tcl/expect to open a blog post and then export latex code.

The tex file is then converted to a pdf.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

test -f "$1" || exit 1

fp="$1"
bn="$(basename "$fp")"
mant="${bn%.*}"

dn="$(dirname "$fp")"

td_thing="$(mktemp -t -d td_thingXXXXXX || echo /dev/null)"
trap "rmdir \"$td_thing\" 2>/dev/null" 0

cd "$dn"

x -ub -sh "$(cmd orspe "$fp")" -m '<' -m : -s "(org-latex-export-to-pdf)" -c m -e "No undo" -m : -s "(kill-window-and-quit-emacsclient)" -c m -i
pdflatex "${mant}.tex"
rm ${mant}.{log,toc,out,aux,tex}

Make the create-portfolio-from-blog script

This script uses the above two scripts to generate pdfs for all of the blog posts.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

unbuffer oci sort-blog-posts-by-date | tac | jq -r .path | awk1 | tv | soak | while IFS=$'\n' read -r line; do
{
    echo "$line" 1>&2
    fp="$line"
    bn="$(basename "$fp")"
    mant="${bn%.*}"

    unbuffer e-org-latex-export-to-pdf "$line" &>/dev/null
    echo "${mant}.pdf"
}
done | pavs

asciinema recording

Combine the pdfs into one

1
2
cd $HOME/blog/posts
eval "pdftk $(cat $DUMP/tmp/scratchY859O5.txt | s join ' ') cat output portfolio.pdf"

Completed portfolio file

Portfolio PDF download