Created
September 21, 2015 14:30
-
-
Save danman01/0a89ce875713bc0515f6 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
pdf_stylesheet="/Users/dkirschner/dev/mapr/apache_spark/ebook/spark-book-theme/pdf/pdf.css" | |
theme_stylesheet="/Users/dkirschner/dev/mapr/apache_spark/ebook/spark-ebook/theme/pdf/pdf.css" | |
print_stylesheet="/Users/dkirschner/dev/mapr/apache_spark/ebook/spark-book-theme/pdf/pdf_print.css" | |
USAGE="Usage: -f input file with either md or html file ending, -o optional output file with pdf ending, -p anything here will turn on print mode, -? or -h prints usage" | |
while getopts “ht:f:o:p” OPTION | |
do | |
case $OPTION in | |
h) | |
echo $USAGE | |
exit 1 | |
;; | |
f) | |
file=$OPTARG | |
;; | |
o) | |
output=$OPTARG | |
;; | |
p) | |
PRINT=1 | |
;; | |
?) | |
echo $USAGE | |
exit | |
;; | |
esac | |
done | |
if [[ -z $file ]] | |
then | |
echo $USAGE | |
exit 1 | |
fi | |
# Check ending. If markdown, convert to html using pandoc. If html, convert html directly to pdf using prince. | |
ending=`echo ${file##*.}` | |
echo "ending is $ending" | |
if [ $ending == "md" ] | |
then | |
# convert supplied markdown file to html using prince | |
# convert markdown to html | |
html=$(echo "$file" | sed 's/\.md/\.html/') | |
echo "converting markdown to html file which will be $html..." | |
`pandoc $file -o $html` | |
remove=1 | |
elif [ $ending = "html" ]; then | |
html=$file | |
else | |
echo $USAGE | |
exit 1 | |
fi | |
# if didn't specify output, just use input file name with pdf ending | |
if [[ -z $output ]]; then | |
pdf=$(echo "$html" | sed 's/html/pdf/') | |
else | |
pdf=$output | |
fi | |
echo "converting html to pdf which will be $pdf" | |
# convert html to pdf | |
if [ -z $PRINT ]; then | |
echo "generating web version of pdf..." | |
prince $html -o $pdf -s $pdf_stylesheet -s $theme_stylesheet | |
else | |
echo "generating print version of pdf..." | |
prince $html -o $pdf -s $pdf_stylesheet -s $theme_stylesheet -s $print_stylesheet | |
fi | |
if [[ $remove == "1" ]]; then | |
# remove the html file we generated earlier | |
rm $html | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment