-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script can be symlinked to. I link to in from $HOME/.local/bin | ||
|
||
# Rule 1: Do only what's necessary in Pandoc | ||
|
||
# Figure out where everything is | ||
SCRIPT=$(realpath $0) | ||
SCRIPT_PATH=$(dirname $SCRIPT) | ||
PANDOC_TEMPLATES=$(dirname $SCRIPT_PATH) | ||
SCRIPT="$(realpath "$0")" | ||
SCRIPT_PATH="$(dirname "$SCRIPT")" | ||
PANDOC_TEMPLATES="$(dirname "$SCRIPT_PATH")" | ||
SHUNN_SHORT_STORY_DIR="$PANDOC_TEMPLATES/shunn/short" | ||
|
||
# Create a temporary data directory | ||
echo "Creating temporary directory." | ||
export PANDOC_DATA_DIR=$(mktemp -d) | ||
export PANDOC_DATA_DIR | ||
PANDOC_DATA_DIR="$(mktemp -d)" | ||
echo "Directory created: $PANDOC_DATA_DIR" | ||
|
||
# Prep the template and reference directories | ||
echo "Extracting $SHUNN_SHORT_STORY_DIR/template.docx to temporary directory." | ||
unzip -ao $SHUNN_SHORT_STORY_DIR/template.docx -d $PANDOC_DATA_DIR/template > /dev/null | ||
unzip -ao $SHUNN_SHORT_STORY_DIR/template.docx -d $PANDOC_DATA_DIR/reference > /dev/null | ||
unzip -ao "$SHUNN_SHORT_STORY_DIR/template.docx" -d "$PANDOC_DATA_DIR/template" > /dev/null | ||
unzip -ao "$SHUNN_SHORT_STORY_DIR/template.docx" -d "$PANDOC_DATA_DIR/reference" > /dev/null | ||
echo "Files extracted." | ||
|
||
# Run pandoc | ||
echo "Running Pandoc." | ||
pandoc $1 \ | ||
pandoc "$1" \ | ||
--from markdown \ | ||
--to docx \ | ||
--lua-filter $SHUNN_SHORT_STORY_DIR/shunnshort.lua \ | ||
--data-dir $PANDOC_DATA_DIR \ | ||
--output $2 | ||
--lua-filter "$SHUNN_SHORT_STORY_DIR/shunnshort.lua" \ | ||
--data-dir "$PANDOC_DATA_DIR" \ | ||
--output "$2" | ||
echo "Pandoc completed successfully." | ||
|
||
# Clean up the temporary directory | ||
echo "Removing $PANDOC_DATA_DIR" | ||
rm -rf $PANDOC_DATA_DIR | ||
rm -rf "$PANDOC_DATA_DIR" | ||
echo "Done." |