build.sh 2.85 KB
Newer Older
Jean Michel Rouly's avatar
Jean Michel Rouly committed
1 2
#!/bin/bash

3

Jean Michel Rouly's avatar
Jean Michel Rouly committed
4 5
set -e

6

Jean Michel Rouly's avatar
Jean Michel Rouly committed
7
# Clean up first
8
echo "Cleaning build directory."
9
clean.sh
Jean Michel Rouly's avatar
Jean Michel Rouly committed
10
mkdir -p tmp
11
mkdir -p webroot
12
mkdir -p webroot/json
Jean Michel Rouly's avatar
Jean Michel Rouly committed
13

14 15 16 17 18 19

echo "Copying static files into webroot."
cp -r static webroot/

echo "Building articles."
for article in pages/articles/*
Jean Michel Rouly's avatar
Jean Michel Rouly committed
20 21
do

22 23 24 25 26 27 28 29
  echo "Operating on $article."

  echo "  Generating asset filenames."
  ID=$(echo $article | sed 's/[^/]*\/[^/]*\///' )
  TITLE_FILE="pages/articles/$ID/title"
  ARTICLE_FILE="pages/articles/$ID/article"
  OVERVIEW_FILE="pages/articles/$ID/overview"
  COPYRIGHT_FILE="pages/articles/$ID/copyright"
30
  ANNOTATIONS_FILE="pages/articles/$ID/annotations.json"
31 32 33 34 35 36

  echo "  Checking file presence."
  if [ ! -f $TITLE_FILE ]; then echo "No file $TITLE_FILE found.  Exiting."; exit; fi
  if [ ! -f $OVERVIEW_FILE ]; then echo "No file $OVERVIEW_FILE found.  Exiting."; exit; fi
  if [ ! -f $ARTICLE_FILE ]; then echo "No file $ARTICLE_FILE found.  Exiting."; exit; fi
  if [ ! -f $COPYRIGHT_FILE ]; then echo "No file $COPYRIGHT_FILE found.  Exiting."; exit; fi
37
  if [ ! -f $ANNOTATIONS_FILE ]; then echo "No file $ANNOTATIONS_FILE found.  Exiting."; exit; fi
Jean Michel Rouly's avatar
Jean Michel Rouly committed
38

39 40 41 42 43
  echo "  Reading data."
  TITLE=$( cat $TITLE_FILE )
  ARTICLE=$( cat $ARTICLE_FILE )
  OVERVIEW=$( cat $OVERVIEW_FILE )
  COPYRIGHT=$( cat $COPYRIGHT_FILE )
Jean Michel Rouly's avatar
Jean Michel Rouly committed
44

45 46 47 48
  echo "  Generating template."
  cat layout/head.html    >  "tmp/$ID.html"
  cat layout/article.html >> "tmp/$ID.html"
  cat layout/foot.html    >> "tmp/$ID.html"
Jean Michel Rouly's avatar
Jean Michel Rouly committed
49

50 51 52 53 54 55 56 57 58 59
  echo "  Populating template with data."
  sed -i -e "s|{{ TITLE }}|$TITLE|" \
         -e "s|{{ ID }}|$(echo $ID)|" \
         -e "s|{{ COPYRIGHT }}|$(echo $COPYRIGHT)|" \
         -e "s|{{ OVERVIEW }}|$(echo $OVERVIEW)|" \
         -e "s|{{ ARTICLE }}|$(echo $ARTICLE)|" \
         "tmp/$ID.html"

  echo "  Moving into webroot."
  mv "tmp/$ID.html" webroot/
60
  cp $ANNOTATIONS_FILE "webroot/json/$ID.json"
61

Jean Michel Rouly's avatar
Jean Michel Rouly committed
62
  ASSETS="pages/articles/$ID/assets"
63 64 65 66 67 68 69 70
  if [ -e $ASSETS ]
  then

    echo "  Copying over assets."
    mkdir -p "webroot/assets/$ID"
    cp -r $ASSETS/* "webroot/assets/$ID"

  fi
Jean Michel Rouly's avatar
Jean Michel Rouly committed
71 72

done
Jean Michel Rouly's avatar
Jean Michel Rouly committed
73

74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

echo "Building site pages."
for page in pages/site/*
do

  echo "Operating on $page."

  echo "  Generating asset filenames."
  ID=$(echo $page | sed 's/[^/]*\/[^/]*\///' )
  TITLE_FILE="pages/site/$ID/title"
  BODY_FILE="pages/site/$ID/body"

  echo "  Checking file presence."
  if [ ! -f $TITLE_FILE ]; then echo "No file $TITLE_FILE found.  Exiting."; exit; fi
  if [ ! -f $BODY_FILE ]; then echo "No file $BODY_FILE found.  Exiting."; exit; fi

  echo "  Reading data."
  TITLE=$( cat $TITLE_FILE )
  BODY=$( cat $BODY_FILE )

  echo "  Generating template."
  cat layout/head.html >  "tmp/$ID.html"
  cat $BODY_FILE       >> "tmp/$ID.html"
  cat layout/foot.html >> "tmp/$ID.html"

  echo "  Populating template with data."
  sed -i -e "s|{{ TITLE }}|$TITLE|" "tmp/$ID.html"

  echo "  Moving into webroot."
  mv "tmp/$ID.html" webroot/

done


echo "Cleaning up."
rmdir tmp