Created
February 20, 2017 09:08
-
-
Save richardp2/438a2dbb42b2d2b82d67638a833b37b9 to your computer and use it in GitHub Desktop.
Rakefile Site Deploy Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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