working with auto title and base level config (toc)
This commit is contained in:
parent
f3c829e3d5
commit
5f25dca762
71
stitch
71
stitch
@ -1,12 +1,23 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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)
|
working_dir=$(pwd)
|
||||||
header="$working_dir/header.md"
|
header="$working_dir/header.md"
|
||||||
|
|
||||||
formatting() {
|
formatting() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
---
|
---
|
||||||
title: $1
|
toc-title: $1
|
||||||
documentclass: report
|
documentclass: report
|
||||||
linkcolor: blue
|
linkcolor: blue
|
||||||
geometry: margin=1in
|
geometry: margin=1in
|
||||||
@ -14,16 +25,52 @@ geometry: margin=1in
|
|||||||
EOF
|
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
|
# creates a temporary file for formatting
|
||||||
formatting "test" > $header
|
formatting "$TITLE" > $header
|
||||||
|
pandoc $header $working_dir/*.md --toc --toc-depth=1 -o "$OUTPUT.pdf"
|
||||||
if [ -z "$outputname" ] ; then
|
|
||||||
outputname=test
|
|
||||||
fi
|
|
||||||
if [ -f "$outputname" ] ; then
|
|
||||||
rm "$outputname"
|
|
||||||
fi
|
|
||||||
pandoc "$working_dir/header.md" "$directory/*.md" -o "$outputname.pdf"
|
|
||||||
|
|
||||||
|
# cleanup
|
||||||
rm "$working_dir/header.md"
|
rm "$working_dir/header.md"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user