Using an upload task

To upload nanoc-generated sites, I use a Rake task that invokes rsync. Depending on the OS you are using, rsync may or may not be installed yet (it is on Mac OS X). The Rake task looks like this:

class String
  def e
    self.gsub('\\', '\\\\').gsub(' ', '\\ ')
  end
end

task :upload do
  # don't use trailing slashes for directories
  local_dir  = '/home/example/example_nanoc_site'
  remote_dir = '/var/www/html' 
  user       = 'example_user'
  host       = 'example.com'

  puts 'Uploading site...'
  system "rsync -rpgzvP #{local_dir.e}/ #{user.e}@#{host.e}:#{remote_dir.e}"
  puts 'Site uploaded.'
end

You'll most likely have to update the local_dir, remote_dir, user and host variables.

This task (invoked like this: rake upload) uploads the contents of local_dir into the remote_dir directory to host, logging in as user.

Depending on how you use your nanoc site, you may wish to skip any Subversion-related directories using the --exclude='.svn' option. There are quite a few more useful rsync options; I recommend checking out the rsync manpage.