| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | # check the required tools; we make these available through the `nix develop` |
| 6 | # shell so you may use that to build the manual |
| 7 | required_tools=("htmlq" "sed" "weasyprint") |
| 8 | for tool in "${required_tools[@]}" |
| 9 | do |
| 10 | if ! [ -x "$(command -v "$tool")" ]; then |
| 11 | echo "Please make sure $tool is accessible." >&2 |
| 12 | exit 1 |
| 13 | fi |
| 14 | done |
| 15 | |
| 16 | # this script fetches the manual content from the remote rendered version at |
| 17 | # arara's website; caveat: chapters have to be manually adjusted |
| 18 | currdir="$PWD" |
| 19 | basedir="$(dirname "$currdir")/website/public/" |
| 20 | baseurl="file://$basedir" |
| 21 | |
| 22 | if [ ! -d "$basedir" ] |
| 23 | then |
| 24 | echo "Please run zola before converting to PDF." >&2 |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | # create a temporary directory to build the manual in; this will be created |
| 29 | # in /tmp, so users of operating systems without that directory must change |
| 30 | # it here |
| 31 | tempdir="/tmp/arara-quickstart" |
| 32 | if [ -d "$tempdir" ] |
| 33 | then |
| 34 | rm -r "$tempdir" |
| 35 | fi |
| 36 | mkdir -p "$tempdir" |
| 37 | cp ./resources/* "$tempdir/" |
| 38 | cd "$tempdir" |
| 39 | |
| 40 | # these files are created in the temporary directory; no need to change |
| 41 | # anything at this point except that the name of the PDF file will be used |
| 42 | # when copying back to the source directory |
| 43 | htmlfile="quickstart.html" |
| 44 | pdffile="arara-quickstart.pdf" |
| 45 | |
| 46 | cat <<EOF > $htmlfile |
| 47 | <!DOCTYPE html> |
| 48 | <html lang="en-US"> |
| 49 | <head> |
| 50 | <meta charset="UTF-8"> |
| 51 | <title>arara</title> |
| 52 | |
| 53 | <meta name="keywords" content="tex, latex, context, build tool, automation"> |
| 54 | <meta name="name" content="The cool TeX automation tool"> |
| 55 | <meta name="description" content="arara is a TeX automation tool based on directives and rules."> |
| 56 | |
| 57 | <link href="file://$tempdir/manual.css" rel="stylesheet"> |
| 58 | </head> |
| 59 | <body> |
| 60 | <article> |
| 61 | <h1>A quickstart guide to arara</h1> |
| 62 | EOF |
| 63 | |
| 64 | # assemble the manual content by fetching chapters from the webpage; |
| 65 | # while doing so assemble the toc for that chapter as well |
| 66 | cat <<EOF >> $htmlfile |
| 67 | $(cat "$(echo "$baseurl" | cut -c8-)quickstart/index.html" | htmlq 'div.content.text' --remove-nodes 'div.heading-text' \ |
| 68 | | tail -n +3 | head -n -1 \ |
| 69 | | sed -r 's/<(\/?)h5/<\1h6/g' | sed -r 's/<(\/?)h4/<\1h5/g' \ |
| 70 | | sed -r 's/<(\/?)h3/<\1h4/g' | sed -r 's/<(\/?)h2/<\1h3/g' \ |
| 71 | | sed -r 's/<(\/?)h1/<\1h2/g') |
| 72 | EOF |
| 73 | |
| 74 | cat <<EOF >> $htmlfile |
| 75 | </body> |
| 76 | </html> |
| 77 | EOF |
| 78 | |
| 79 | # convert the created HTML manual to PDF |
| 80 | weasyprint -u "$baseurl" "$htmlfile" "$pdffile" |
| 81 | |
| 82 | # change back to the docs directory and copy output PDF there |
| 83 | cd "$currdir" |
| 84 | cp "$tempdir/$pdffile" ./ |