Dyce & Sons Ltd.

Helping IT since 1993

Fun & Games

Friday 30th May, 2014

I’ve found a few wrinkles to working with docpad, and some fixes that bear mentioning.

Clean Slate

As mentioned in the previous post, docpad doesn’t offer (yet) a plugin for deployment via RSync… but there is a gist, courtesy of Jayson Harshbarger, that for setting one up as a bash script.

One wrinkle, when deploying a previously locally tested/built site to a remote server is the need to wipe the previous output. This is especially irritating if you’re still fiddling with the site templates rather than just the content.

Here’s an updated script that does that:

#!/bin/bash
set -o nounset
set -o errexit

NFLAG=""

while getopts ":n" opt; do
  case $opt in
    n)
      NFLAG="-n"
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      ;;
  esac
done

# Set the environment by loading from the file "environment" in the same directory
DIR="$( cd "$( dirname $( dirname "$0" ) )" && pwd)"
source "$DIR/.env"


#### Added steps

# empty the caches
echo "Emptying npm caches"
rm -rf ~/.npm
npm cache clear

# empty the output folder
echo "Deleting ${DIR}/${DEPLOY_SOURCE_DIR}"
rm -Rf $DEPLOY_SOURCE_DIR

####

#### Changed due to changes in .env file

echo "Deploying ${DIR}/${DEPLOY_SOURCE_DIR}/ to ${DEPLOY_ACCOUNT}@${DEPLOY_SERVER}:${DEPLOY_DEST_DIR}/"

docpad generate --env static
chmod -R og+Xr "${DEPLOY_SOURCE_DIR}/"
rsync $NFLAG -rvzp --delete --exclude-from="$DIR/.deployignore" "${DIR}/${DEPLOY_SOURCE_DIR}/" "${DEPLOY_ACCOUNT}@${DEPLOY_SERVER}:${DEPLOY_DEST_DIR}/"

Of course there the subtle change means that you’ll also need to adjust the .env file discussed in the gist, so that there aren’t any trailing slashes on the directories.

#!/bin/bash
DEPLOY_SOURCE_DIR="out"
DEPLOY_DEST_DIR="~/my/remote/directory"
DEPLOY_SERVER=myserverip_or_dnsname
DEPLOY_ACCOUNT=myusername
DEPLOY_PASSWORD=mypassword

Naughty Filenames

Oh how this one tickled me…

Of course, don’t use characters that require entities in html - e.g. & - in your filenames. Goes without saying. But, don’t include the word ‘docpad’ in your documents to be rendered. It seems to break docpad’s file handling in quirky ways.