Skip to content

Instantly share code, notes, and snippets.

@richardp2
Created February 20, 2017 09:08
Show Gist options
  • Save richardp2/438a2dbb42b2d2b82d67638a833b37b9 to your computer and use it in GitHub Desktop.
Save richardp2/438a2dbb42b2d2b82d67638a833b37b9 to your computer and use it in GitHub Desktop.
Rakefile Site Deploy Script
# The following task was adapted from one written by Shane Burkhart
# Source: http://www.shaneburkhart.me/2013/12/07/rake-task-to-publish-drafts-in-jekyll.html
desc "Publish draft posts and update the date field"
task :publish, [:file] do |t, args|
require "time"
if args[:file]
file = "_drafts/#{args[:file]}"
text = File.read(file)
time = Time.now.iso8601.gsub!('T', ' ')
text.gsub!(/^date.*$/, "date: #{time}")
today = Time.now.strftime("%Y-%m-%d")
post_name = file.split("/").last
dest = "_posts/#{today}-#{post_name}"
File.open(dest, 'w') {|f| f.write(text) }
puts "Published file #{post_name}"
File.delete(file)
puts "Deleted draft file #{post_name}"
else
puts "Incorrect usage of the :publish task"
puts "\n\tUsage:"
puts "\trake publish[draft-post.md]"
puts "\nPlease try again"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment