aboutsummaryrefslogtreecommitdiff
path: root/gen.sh
blob: b708717ecda961c7bd2e287dac7be896c29dffba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
MARKDOWN_DIR="Markdown"
MARKDOWN_DIR_LENGTH=$(expr 1 + ${#MARKDOWN_DIR})
HTML_DIR="Page"

# write_html_file: FilePath -> FilePath -> IO ()
write_html_file () {
  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…"

SELECTOR="${MARKDOWN_DIR}/*.md ${MARKDOWN_DIR}/**/*.md"
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 "$MARKDOWN_FILENAME" "$HTML_FILENAME"
done

write_html_file "$MARKDOWN_DIR/Index.md" index.html

rm -f makeup && ln -s . makeup

echo "> Done !"