diff options
Diffstat (limited to 'gen.sh')
-rwxr-xr-x | gen.sh | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -3,31 +3,29 @@ MARKDOWN_DIR="Markdown" MARKDOWN_DIR_LENGTH=$(expr 1 + ${#MARKDOWN_DIR}) HTML_DIR="Page" -# clean_html_files: IO () -clean_html_files () { - rm -rf "$HTML_DIR" -} - # write_html_file: FilePath -> FilePath -> IO () write_html_file () { - mkdir -p $(dirname "$2") - cat Fragments/begin.html > "$2" - pandoc -t html "$1" >> "$2" - cat Fragments/end.html >> "$2" + MARKDOWN_FILENAME="$1" + HTML_FILENAME="$2" + + BEGIN=$(cat Fragments/begin.html) + CONTENT=$(pandoc -t html "$MARKDOWN_FILENAME") + END=$(cat Fragments/end.html) + + mkdir -p $(dirname "$HTML_FILENAME") + echo "$BEGIN$CONTENT$END" > "$HTML_FILENAME" } echo "" echo "> Generating HTML files…" -clean_html_files - SELECTOR="${MARKDOWN_DIR}/*.md ${MARKDOWN_DIR}/**/*.md" -for FILENAME in $SELECTOR; do - WITHOUT_DIR=${FILENAME:$MARKDOWN_DIR_LENGTH} +for MARKDOWN_FILENAME in $SELECTOR; do + WITHOUT_DIR=${MARKDOWN_FILENAME:$MARKDOWN_DIR_LENGTH} WITHOUT_EXT=${WITHOUT_DIR%.*} HTML_FILENAME="$HTML_DIR/$WITHOUT_EXT.html" - write_html_file "$FILENAME" "$HTML_FILENAME" + write_html_file "$MARKDOWN_FILENAME" "$HTML_FILENAME" done write_html_file "$MARKDOWN_DIR/Index.md" index.html |