#!/usr/bin/env bash # # Book compiler # # Parameters BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" DIRNAME="`dirname $0`" BASEDIR="$DIRNAME/.." CONTENT="content/notes" OUTPUT="${1:-notes}" REVISION="$2" DATE="$3" LANG="`grep lang _common.yml _book.yml _notes.yml 2> /dev/null | tail -1 | cut -d : -f 3 | sed -e 's/"//g' -e 's/ //g'`" # Set the language if [ -z "$LANG" ]; then LANG="en" fi # Set structure and templates STRUCTURE="structure/notes/$LANG" TEMPLATES="templates/notes/$LANG" # Update _output.yml with language information sed -e "s|%%lang%%|$LANG|g" $BASEDIR/templates/_output.yml > _output.yml # Remove any dangling output files rm -f $OUTPUT.md # Notes config cat _notes.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md cat _common.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md # Bibliography $BASEDIR/bin/biblio-yml > _biblio.yml cat _biblio.yml >> $OUTPUT.md # 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 # Content if [ -d "$CONTENT" ]; then find $CONTENT -type f | grep '\.md$' | sort | while read file; do cat $file >> $OUTPUT.md echo "" >> $OUTPUT.md done fi # Bibliography section cat $BASEDIR/$TEMPLATES/bibliography.md >> $OUTPUT.md # 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 -s $OUTPUT.md notes.Rmd