Newer
Older
Import / applications / MakePDF / Website / generate.sh
#!/bin/bash

SITE_NAME="WickedDocs"
HOST="subflexion.com"
TWITTER_ID="WickedDocs"
DEST_DIR="${HOME}/${HOST}/${SITE_NAME}"
CLEAN_MODE=0

# Generate the news page
echo "Generating news feed"
python news.py > pages/news.htm
echo "Generating rss feed"
python rss.py > rss.xml


if [ "$1" == "--clean" ]
then
  CLEAN_MODE=1
  echo "Cleaning..."
  rm *~
else
  mkdir -p "$DEST_DIR"
  cp style.css "$DEST_DIR"
  cp rss.xml "$DEST_DIR"
  cp -Ra images "$DEST_DIR"
  cp -Ra fonts "$DEST_DIR"
  cp -Ra externals "$DEST_DIR"
  cp -Ra payment "$DEST_DIR"
  cp -Ra support "$DEST_DIR"
  cp -Ra updates "$DEST_DIR"
  cp -Ra activation "$DEST_DIR"
  chmod -R a+r "$DEST_DIR/externals"
fi

ApplyTemplates()
{
  TITLE="$1"
  SUB_TITLE="$2"
  PAGE_BASENAME="$3"
  URL_BASE=""
  if [ "$CLEAN_MODE" != "1" ]
  then

    #cat tmpl/header.htm | sed "s/\(\$TITLE\)/$TITLE/g" > "$DEST_DIR/$PAGE_BASENAME.html"
    
    # TODO:
    #   This isn't so clever, things like "/* blah */" get expanded out as list of files from root directory, eg: "/.*" etc
    #   Better would be to very explicitly expand out the variables, TITLE, SUB_TITLE and PAGE_BASENAME
    #   However this wouldn't minify. Also currently the tmpl file has bash script in it to add logic.
    # Workaround is to add escaping to places where the wrong thing happens

    # Also removing the white space means can't do end of line comments in code. If fix is using /* */ comments, but they
    # have there own problem.

    echo "Generating $PAGE_BASENAME"


    # This next command makes it possible for variable expansion to happen when applying the header
    echo `eval $'cat <<\002\n'"$(<tmpl/header.htm)"$'\n\002'` > "$DEST_DIR/$PAGE_BASENAME.html"
    echo `eval $'cat <<\002\n'"$(<tmpl/title.htm)"$'\n\002'` >> "$DEST_DIR/$PAGE_BASENAME.html"

    # The way this does the echo of the cat command causes the white space to be removed - the tr allows things to be escaped
    echo `cat pages/$PAGE_BASENAME.htm` | tr -d '\\' >> "$DEST_DIR/$PAGE_BASENAME.html"
    
    # This next command makes it possible for variable expansion to happen when applying the footer
    echo `eval $'cat <<\002\n'"$(<tmpl/footer.htm)"$'\n\002'` >> "$DEST_DIR/$PAGE_BASENAME.html"


    # For debugging, don't remove the white space
    # cat pages/$PAGE_BASENAME.htm tmpl/footer.htm >> "$DEST_DIR/$PAGE_BASENAME.html"
    # | sed -e "s/^[ \t]*//g" -e ":a;N;$!ba;s/\n//g" 
  else
    rm "$DEST_DIR/$PAGE_BASENAME.html"
  fi
}

ApplyTemplates  "About"         "" index
ApplyTemplates  "Downloads"     "" download
ApplyTemplates  "Features"      "" features
ApplyTemplates  "Screenshots"   "" screenshots
ApplyTemplates  "News"          "" news
ApplyTemplates  "Documentation" "" documentation
ApplyTemplates  "Help"          "" help
ApplyTemplates  "Support"       "" support
ApplyTemplates  "F.A.Q."        "<br>Frequently Asked Questions" faq
ApplyTemplates  "Community"     "" community
ApplyTemplates  "Registration"  "" register
ApplyTemplates  "Thank You"     "" success
ApplyTemplates  "Cancelled"     "" cancelled
ApplyTemplates  "Contact"       "" contact
ApplyTemplates  "Legal"         "" legal
ApplyTemplates  "Licenses"      "" licenses
ApplyTemplates  "EULA"          "<br>End User License Agreement" eula

# Generate documentation pages
echo `cat tmpl/plain_header.htm pages/documentation.htm tmpl/plain_footer.htm` > "$DEST_DIR/app_docs.html"

# Generate headers and footers suitable for php inclusion for generated error pages
TITLE=""
SUB_TITLE=""
URL_BASE="/WickedDocs/"
echo `eval $'cat <<\002\n'"$(<tmpl/header.htm)"$'\n\002'` > "$DEST_DIR/header.html"
echo `cat tmpl/footer.htm` | tr -d '\\' > "$DEST_DIR/footer.html"