Bläddra i källkod

Add some metadata handling to booxdown script

Samuel W. Flint 2 år sedan
förälder
incheckning
00c13d8bb6
1 ändrade filer med 22 tillägg och 4 borttagningar
  1. 22 4
      booxdown

+ 22 - 4
booxdown

@@ -2,8 +2,13 @@
 
 MDFILE=$1
 PDFFILE=$(basename $MDFILE .md).pdf
-
 FILE=$(mktemp XXXXXXXXXX-${MDFILE})
+HAS_METADATA=0
+
+if head -n 1 ${MDFILE} | grep -- '---' > /dev/null ; then
+    echo "Metadata Block Found"
+    HAS_METADATA=1
+fi
 
 cat <<EOF >> $FILE
 ---
@@ -24,14 +29,27 @@ monofontoptions:
 csquotes: true
 highlight-style: monochrome
 citemethod: biblatex
+pdfa: true
 hyperrefoptions:
  - breaklinks=true
  - bookmarks=true
-...
 EOF
 
-cat $MDFILE >> $FILE
+if [ $HAS_METADATA -eq 1 ] ; then
+    cat $MDFILE | sed '1 d' >> $FILE
+else
+    echo "..." >> $FILE
+    cat $MDFILE >> $FILE
+fi
+
+echo "Processing file to PDF."
+pandoc -f markdown \
+       -s -t pdf \
+       --highlight-style monochrome \
+       --pdf-engine='lualatex' \
+       -o $PDFFILE \
+       $FILE
 
-pandoc -f markdown -t pdf --highlight-style monochrome --pdf-engine='lualatex' -o $PDFFILE $FILE
+echo "Done."
 
 rm $FILE