Last active
January 1, 2016 03:29
-
-
Save gr4y/8085631 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
task :deploy do | |
sh "rsync -rt _site #{USER}@#{SERVER}:~/blog" | |
end |
This file contains hidden or 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
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 |
This file contains hidden or 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
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