Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created January 28, 2014 01:20
Show Gist options
  • Save miyagawa/8660777 to your computer and use it in GitHub Desktop.
Save miyagawa/8660777 to your computer and use it in GitHub Desktop.
require 'erb'
desc "build static files"
task :build do |t|
system "bundle exec jekyll build"
end
desc "push site content to the production environment"
task :push => [:build] do |t|
system "rsync -avz --delete _site/ USER@REMOTE:/var/www/rebuild.fm/htdocs/"
end
task :maint do |t|
system "rsync -avz --delete _scripts/ USER@REMOTE:/var/www/rebuild.fm/scripts/"
end
desc "run web server"
task :server do
system "bundle exec jekyll server -w"
end
desc "create new markdown off of the template and open it"
task :new do
date = (Time.now + 24 * 60 * 60).strftime('%Y-%m-%d')
@episode = next_episode
md = "_posts/#{date}-#{@episode}.md"
content = ERB.new(File.read('_posts/_new_episode.erb')).result
File.open(md, 'w') {|f| f.write(content) }
system "open", md
end
desc "encode AIFF files to MP3 using LAME Encoder"
task :encode do
ep = ENV['EP'] or raise 'EP is required'
source = "#{ENV['HOME']}/Music/GarageBand/Podcast ep#{ep}.output.aif"
output = "./_media/podcast-ep#{ep}.mp3"
File.exists?(source) or raise "source file #{source} does not exist"
if File.exists?(output)
print "#{output} already exists. Hit RET to proceed: "
STDIN.gets
end
system "lame",
"--tt", "Podcast ep#{ep}",
"--ta", "Tatsuhiko Miyagawa",
"--tl", "Rebuild",
"--ty", Time.now.year.to_s,
"--ti", "./images/icon1400.jpg",
"-q", "2",
"-b", "64", "-m", "m",
source, output
end
desc "upload mp3 files to the cache server"
task :upload do
system "rsync -avz --progress _media/ USER@REMOTE:/var/www/cache.rebuild.fm/htdocs/"
end
def next_episode
Dir.glob('_posts/*.md').map {|f| /-(\d+).md/.match(f)[1].to_i }.max + 1
end
desc "ping updates to FeedPress"
task :ping do |t|
require 'xmlrpc/client'
server = XMLRPC::Client.new("feedpress.it", "/ping", 80)
begin
result = server.call("weblogUpdates.ping", "Rebuild", "http://rebuild.fm/")
p result
rescue Exception => e
p e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment