Skip to content

Instantly share code, notes, and snippets.

@niklas-ourmachinery
Last active September 18, 2019 14:27
Show Gist options
  • Save niklas-ourmachinery/2d1fc4f8013c11ca410f4983aae32d52 to your computer and use it in GitHub Desktop.
Save niklas-ourmachinery/2d1fc4f8013c11ca410f4983aae32d52 to your computer and use it in GitHub Desktop.
Ruby four-liner for uploading web site from Hugo to FTP
# upload.rb URL [SINCE]
#
# Uploads website generated by Hugo (or other static web site generator) to the URL using wput.
#
# URL URL of ftp server, including user name and password
# (e.g. ftp://USER:PASSWORD@site.com/public_html/)
#
# SINCE upload files changed since this git revision
# if not specified, HEAD^ is used, i.e. the latest changes are uploaded
#
# Assumes that generated web pages are checked into git (you probably want to do that
# anyway so you can track changes when you update the Hugo version, change layouts, etc).
#
# Assumes that generated web pages are found in the "public/" directory.
URL = ARGV[0] or raise "URL needed (ftp://USER:PASSWORD@site.com/public_html/)"
SINCE = ARGV[1] || "HEAD^"
MODIFIED = `git diff --name-only #{SINCE}`.lines.map {|x| x.strip}.select{|x| x[/^public/]}.join(" ")
system("wput -u --basename=public/ #{MODIFIED} #{URL}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment