From f58970dcc858be111fe46e7c8dc42f1ac947d025 Mon Sep 17 00:00:00 2001 From: sperka Date: Thu, 18 Jun 2015 10:40:56 -0500 Subject: [PATCH] improved doc gen script; converts rst files to ipynb and html and stores both --- docs/make_rst_htmls.sh | 35 +++++++++++++++++++++++++-------- docs/rst2html.sh | 44 +++++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/docs/make_rst_htmls.sh b/docs/make_rst_htmls.sh index eeaeddbc4..5a557babb 100644 --- a/docs/make_rst_htmls.sh +++ b/docs/make_rst_htmls.sh @@ -1,14 +1,18 @@ #!/bin/bash # set target output directory -TARGETDIR=_build/html +HTMLDIR=_build/html +IPYNBDIR=_build/ipynb # if does not exist, create it -if [ ! -d "$TARGETDIR" ]; then - mkdir -p $TARGETDIR +if [ ! -d "$HTMLDIR" ]; then + mkdir -p $HTMLDIR +fi +if [ ! -d "$IPYNBDIR" ]; then + mkdir -p $IPYNBDIR fi -# files to load from +# files' path FILES=tutorials/*.rst # convert the files @@ -16,10 +20,25 @@ for f in $FILES do base=$(basename $f) fname="${base%.*}" - echo "Converting $f..." - sh rst2html.sh $f $TARGETDIR/$fname.html + + echo "Converting $f and moving results..." + sh rst2html.sh $f $IPYNBDIR/$fname.ipynb $HTMLDIR/$fname.html + #echo "sh rst2html.sh $f $IPYNBDIR/$fname.ipynb $HTMLDIR/$fname.html" done # copy assets next to htmls -echo "Copying assets/ to target directory" -cp -r assets/ $TARGETDIR/assets/ \ No newline at end of file +echo "Copying assets/ to html directory" + +# copy assets/ dir to HTMLDIR/ -- but don't delete if they're the same +if [ -d "$HTMLDIR/assets" ]; then + ASSETS_ABSPATH_REAL=`cd "./assets/"; pwd` + ASSETS_ABSPATH_TARGET=`cd "$HTMLDIR/assets"; pwd` + + if [ $ASSETS_ABSPATH_REAL -ne $ASSETS_ABSPATH_TARGET ]; then + if [ -d "$HTMLDIR/assets" ]; then + rm -rf $HTMLDIR/assets + fi + + cp -r assets/ $HTMLDIR/assets/ + fi +fi \ No newline at end of file diff --git a/docs/rst2html.sh b/docs/rst2html.sh index e4cbff367..bf153a318 100644 --- a/docs/rst2html.sh +++ b/docs/rst2html.sh @@ -3,38 +3,50 @@ # Creates HTML that includes webgl visualization # # Input: file.rst -# Output: file.html +# Output: file.ipynb and file.html # Tools required: # - pandoc # - notedown # - ipython -# example: rst2html.sh file.rst file.html +# example: rst2html.sh file.rst file.ipynb file.html INPUTFILE=$(basename $1) INPUTDIR=$(dirname $1) -FILE="${INPUTFILE%.*}" -OUTPUT=$2 +FILENAME="${INPUTFILE%.*}" -# if output file not provided -if [ -z "$OUTPUT" ]; then - OUTPUT=$INPUTDIR/$FILE.html +OUTPUT_IPYNB=$2 +OUTPUT_HTML=$3 + +# if html output file not provided +if [ -z "$OUTPUT_HTML" ]; then + OUTPUT_HTML=$INPUTDIR/$FILENAME.html +fi + +# if ipynb output not provided +if [ -z "$OUTPUT_IPYNB" ]; then + OUTPUT_IPYNB=$INPUTDIR/$FILENAME.ipynb fi -OUTPUTDIR=$(dirname $OUTPUT) +# check output dirs +OUTPUTDIR_IPYNB=$(dirname $OUTPUT_IPYNB) +OUTPUTDIR_HTML=$(dirname $OUTPUT_HTML) +if [ ! -d "$OUTPUTDIR_IPYNB" ]; then + mkdir -p $OUTPUTDIR_IPYNB +fi +if [ ! -d "$OUTPUTDIR_HTML" ]; then + mkdir -p $OUTPUTDIR_HTML +fi # convert RST to temp MD -pandoc -i $1 -o $FILE.md +pandoc -i $1 -o $FILENAME.md +echo "Converting $INPUTFILE to $OUTPUT_IPYNB" # convert temp MD to IPYNB -notedown $FILE.md > $FILE.ipynb +notedown $FILENAME.md > $OUTPUT_IPYNB # delete temp MD -rm $FILE.md +rm $FILENAME.md # convert ipynb to html with custom template -ipython nbconvert --to html --template ./tpl/mbuild_ipynb_template.tpl $FILE.ipynb --output $OUTPUT -mv $FILE.ipynb $OUTPUTDIR/ - -# don't delete temp ipynb -#rm $FILE.ipynb \ No newline at end of file +ipython nbconvert --to html --template ./tpl/mbuild_ipynb_template.tpl $OUTPUT_IPYNB --output $OUTPUT_HTML