2026-09-10 10:48:36 +02:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
2026-09-10 12:21:32 +02:00
|
|
|
basedir="$(dirname "$0")"
|
|
|
|
|
basedir="$(realpath "$basedir")"
|
|
|
|
|
cd "$basedir"
|
2026-09-10 10:48:36 +02:00
|
|
|
name="$(basename "$(pwd)")"
|
|
|
|
|
|
2026-09-11 12:04:24 +02:00
|
|
|
# Check if we want to run against a certain translation
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
|
echo "Please specify the language you want to build (eg. fr)"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
TARGETLANG="$1"
|
|
|
|
|
SOURCEFILE="main.${TARGETLANG}.typ"
|
|
|
|
|
TARGETFILE="$name".$TARGETLANG.pdf
|
|
|
|
|
TARGETFILEBOOK="$name".${TARGETLANG}-book.pdf
|
|
|
|
|
|
|
|
|
|
if ! typst compile --root .. ./"$SOURCEFILE" ./"$TARGETFILE"; then
|
|
|
|
|
echo "Failed to compile "$name"/"$SOURCEFILE". Please fix errors and run me again."
|
2026-09-10 12:21:32 +02:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Compiled read mode. Now compiling print mode."
|
|
|
|
|
|
|
|
|
|
if ! command -v pdfbook2; then
|
|
|
|
|
echo "ERROR: pdfbook2 not installed. Not compiling print mode."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
t="$(mktemp --suffix=.pdf)"
|
2026-09-11 12:04:24 +02:00
|
|
|
typst compile --input format=booklet --root .. ./"$SOURCEFILE" "$t"
|
2026-09-10 12:21:32 +02:00
|
|
|
|
|
|
|
|
# Need to be in the folder there for it to work, otherwise it
|
|
|
|
|
# tries to rename from current partition to /tmp which of course fails
|
|
|
|
|
parent="$(dirname "$t")"
|
|
|
|
|
newFileName="$(basename "$t" .pdf)-book.pdf"
|
|
|
|
|
newFile="$parent"/"$newFileName"
|
|
|
|
|
cd "$parent"
|
|
|
|
|
|
|
|
|
|
pdfbook2 --paper=a4paper "$t" --no-crop --outer-margin=0 --inner-margin=0 --top-margin=0 --bottom-margin=0
|
|
|
|
|
|
|
|
|
|
cd "$basedir"
|
2026-09-11 12:04:24 +02:00
|
|
|
cp "$newFile" "$TARGETFILEBOOK"
|
|
|
|
|
echo "Booklet available in $TARGETFILEBOOK"
|