53 lines
1.2 KiB
Bash
53 lines
1.2 KiB
Bash
|
|
#!/bin/zsh
|
||
|
|
###
|
||
|
|
# a-preview
|
||
|
|
###
|
||
|
|
# Previews an md file (or other) as a Almanack page
|
||
|
|
###
|
||
|
|
#
|
||
|
|
# Note: this is a clumsy hack from the very early days (pre-Django) of
|
||
|
|
# Almanack, and may well be deprecated. And I say that from the pre-Django days
|
||
|
|
# of Almanack.
|
||
|
|
|
||
|
|
|
||
|
|
function open_html() {
|
||
|
|
if [[ $# -eq 0 ]]; then
|
||
|
|
echo "Usage: open_html <file>"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
local file_to_open="$1"
|
||
|
|
|
||
|
|
case "$OSTYPE" in
|
||
|
|
linux-gnu*)
|
||
|
|
xdg-open "$file_to_open"
|
||
|
|
;;
|
||
|
|
darwin*)
|
||
|
|
open "$file_to_open"
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
}
|
||
|
|
|
||
|
|
# Check if ALMANACK_ROOT is defined
|
||
|
|
if [[ -z "$ALMANACK_ROOT" ]]; then
|
||
|
|
echo "Error: ALMANACK_ROOT is not defined."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Check for one command line argument
|
||
|
|
if [[ $# -ne 1 ]]; then
|
||
|
|
echo "Usage: $(basename $0) <input_file.md>"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
WEB_ROOT=$ALMANACK_ROOT/web/static
|
||
|
|
WEB_RESOURCES=$WEB_ROOT/res
|
||
|
|
PANDOC_ASSETS=$ALMANACK_ROOT/assets/pandoc/
|
||
|
|
|
||
|
|
basename=${1%.*}
|
||
|
|
|
||
|
|
# pandoc -i $1 -B $WEB_RESOURCES/_header.html -c $WEB_RESOURCES/almanack.css --standalone -o $basename.html
|
||
|
|
pandoc --data-dir $PANDOC_ASSETS --metadata-file frontpage.json -i $1 --standalone -o $basename.html
|
||
|
|
|
||
|
|
open_html "$basename.html"
|