Skip to content

Instantly share code, notes, and snippets.

@gr4y
Last active January 1, 2016 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr4y/8085631 to your computer and use it in GitHub Desktop.
Save gr4y/8085631 to your computer and use it in GitHub Desktop.
task :deploy do
sh "rsync -rt _site #{USER}@#{SERVER}:~/blog"
end
require 'reduce'
task :minify do
puts "\n## Compressing static assets"
original = 0.0
compressed = 0
Dir.glob("_site/**/*.*") do |file|
case File.extname(file)
when ".css", ".gif", ".html", ".jpg", ".jpeg", ".js", ".png", ".xml"
puts "Processing: #{file}"
original += File.size(file).to_f
min = Reduce.reduce(file)
File.open(file, "w") do |f|
f.write(min)
end
compressed += File.size(file)
else
puts "Skipping: #{file}"
end
end
puts "Total compression %0.2f\%" % (((original-compressed)/original)*100)
end
task :publish do
date = Time.now.strftime("%Y-%m-%d")
files = Dir["_drafts/*.markdown", "_drafts/*.md"]
files.each_with_index do |file, index|
puts "#{index + 1}: #{file}".sub("_drafts/", "")
end
print "> "
number = $stdin.gets
if number =~ /\D/
filename = files[number.to_i - 1]
yaml = YAML.load_file(filename)
title = yaml['title'].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
published_filename = "_posts/#{date}-#{title.downcase}.md"
FileUtils.mv(filename, published_filename)
puts "#{filename} => '#{published_filename}'."
else
puts "Please choose a draft by the assigned number."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment