#!/usr/bin/env bash # # Book compiler # # Parameters BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" DIRNAME="`dirname $0`" BASEDIR="$DIRNAME/.." STRUCTURE="structure/book" OUTPUT="${1:-book}" REVISION="$2" DATE="$3" # Remove any dangling output files rm -f $OUTPUT.md $OUTPUT.Rmd # Bookup config cat _book.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md cat _common.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md # Bibliography find -name _biblio.yml | while read file; do cat $file >> $OUTPUT.md ; echo "" >> $OUTPUT.md done # YAML headers for file in $BASEDIR/$STRUCTURE/00*.yml; do cat $file >> $OUTPUT.md echo "---" >> $OUTPUT.md done # Markdown headers for file in $BASEDIR/$STRUCTURE/00*.md; do cat $file >> $OUTPUT.md echo "" >> $OUTPUT.md done # Sections find content/sections -type f | grep '\.md$' | sort | while read file; do cat $file >> $OUTPUT.md echo "" >> $OUTPUT.md cat $BASEDIR/templates/book/references.md >> $OUTPUT.md echo "" >> $OUTPUT.md done # Footers for file in $BASEDIR/$STRUCTURE/99*.md; do cat $file >> $OUTPUT.md echo "" >> $OUTPUT.md done # Revision information sed -i -e "s|%%revision%%|$REVISION|g" -e "s|%%date%%|$DATE|g" $OUTPUT.md # Post-processing if [ -e "snippets/terminology.sed" ]; then sed -i -f snippets/terminology.sed $OUTPUT.md fi # Symlink as a Bookdown source ln -sf $OUTPUT.md $OUTPUT.Rmd