Skip to content

Commit

Permalink
Make buildGuidePDF.bash easier to reuse in other domains
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid committed May 16, 2024
1 parent 4056834 commit ce611b0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scripts/buildGuidePDF.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

filename="openrndr-guide"
domain="guide.openrndr.org"
path="" # /some/folder/ if the guide is not located at /

mkdir -p /tmp/manual
cd /tmp/manual || exit

Expand All @@ -9,7 +13,7 @@ cd /tmp/manual || exit
# sed(2) deletes from each line the " character and everything that follows, leaving the clean URL
# tail deletes the first line, which contains a lonely <nav> tag

urlstr=$(curl -s "https://guide.openrndr.org" | grep -o -E '<nav .*</nav>' | sed "s/href=\"\//href=\"\nhttps:\/\/guide.openrndr.org\//g" | sed "s/\".*//g" | tail +2)
urlstr=$(curl -s "https://$domain$path" | grep -o -E '<nav .*</nav>' | sed "s/href=\"\//href=\"\nhttps:\/\/$domain\//g" | sed "s/\".*//g" | tail +2)

# convert a long string into an array
urls=($urlstr)
Expand All @@ -22,11 +26,13 @@ echo "Found $length URLs"
# one by one create NNNN.pdf files from each URL
for (( i=0; i<${length}; i++ ));
do
echo "# Page $i of $length"
padded=$(printf "%04d" $i)
wkhtmltopdf ${urls[$i]} $padded.pdf
done

date=$(date +"%F")

# finally join all the PDF files into one
pdfunite *.pdf /tmp/openrndr-guide-$date.pdf
pdfunite *.pdf /tmp/$filename-$date.pdf

0 comments on commit ce611b0

Please sign in to comment.