working with auto title and base level config (toc)

This commit is contained in:
spinach 2023-02-28 14:45:43 -05:00
parent f3c829e3d5
commit 5f25dca762

71
stitch
View File

@ -1,12 +1,23 @@
#!/usr/bin/env bash
usage() {
cat <<EOF
usage $0 [-o OUTPUT][-t TITLE][-h]
Options:
-o, --output saves file to OUTPUT.pdf in current directory
-t, --title title for the OUTPUT.pdf
-h, --help show this message
EOF
}
working_dir=$(pwd)
header="$working_dir/header.md"
formatting() {
cat <<EOF
cat <<EOF
---
title: $1
toc-title: $1
documentclass: report
linkcolor: blue
geometry: margin=1in
@ -14,16 +25,52 @@ geometry: margin=1in
EOF
}
echo "$header"
# parsing long form
for arg in "$@"; do
shift
case "$arg" in
'--help') set -- "$@" '-h' ;;
'--title') set -- "$@" '-t' ;;
'--output') set -- "$@" '-o' ;;
*) set -- "$@" "$arg" ;;
esac
done
# parsing args
while getopts "ht:o:" opt ; do
case "$opt" in
'h')
usage
exit 0
;;
't')
TITLE="$OPTARG"
;;
'o')
OUTPUT="$OPTARG"
;;
'?')
usage
exit 1
;;
esac
done
if [ -z "$OUTPUT" ] ; then
# default to folder name
OUTPUT=$(echo "$working_dir" | awk -F '/' '{print $NF}')
fi
if [ -z "$TITLE" ] ; then
# defaults to output which will default to directory name
TITLE="$OUTPUT"
fi
# creates a temporary file for formatting
formatting "test" > $header
if [ -z "$outputname" ] ; then
outputname=test
fi
if [ -f "$outputname" ] ; then
rm "$outputname"
fi
pandoc "$working_dir/header.md" "$directory/*.md" -o "$outputname.pdf"
formatting "$TITLE" > $header
pandoc $header $working_dir/*.md --toc --toc-depth=1 -o "$OUTPUT.pdf"
# cleanup
rm "$working_dir/header.md"