Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
dirty hack of a rakefile I use to upload new images to cloudfront for jekyll blog posts
# when I write new blog posts I usually have a temporary folder called new_post on my desktop
# that I place images I want to upload to amazon s3 (which is distributed as CF) and then
# get the appropriate URLs to put the images in my blog post
# I usually save files as some_slug.png and some_slug_1200.png
# with the latter being a larger version (1200px wide) of the first.
# a typical upload will include 20 files. 2 versions of some (sm and lg), and some orphans
# so this compares filenames and if it detects a larger version of a file,
# it links the the smaller image to the larger image (i use fancyzoom on my site)
# if not, it just links to the image
desc 'upload imgs to cloudfront'
task :cloudfront do
puts 'uploading images in ~/Desktop/new_post/ to cf'
post_dir = "/Users/Stammy/Desktop/new_post/"
month ="%m")
year ="%Y")
sh "s3cmd put --acl-public --guess-mime-type #{post_dir}* s3://pstam-cloud/uploads/#{year}/#{month}/"
# create URLs for handy copying
# detect large version of same image and link it to smaller version
# or just provide img src to orphan if no larger version
# works b/c Dir.glob returns files alpha by extension
# was going to refactor to look cleaner.. but it works just fine
puts "Uploaded. Here are your CF URLs \n\n"
img_urls = ''
images = Dir.glob("*.{png,gif,jpg}")
images.each_with_index do |image, index|
cur = image
desc = cur.gsub('pstam_','').gsub('_',' ')[0...-4].capitalize
if !images[index+1].nil?
nxt = images[index+1]
if cur.gsub(/_1[0-9]00/,'')[0...-4] == nxt.gsub(/_1[0-9]00/,'')[0...-4]
if /_1[0-9]00/.match(image)
large = cur
small = nxt
elsif /_1[0-9]00/.match(nxt)
large = nxt
small = cur
img_urls += <<-HTML
<div class="center"><a href="{year}/#{month}/#{large}" title="#{desc}"><img src="{year}/#{month}/#{small}" alt="#{desc}"/></a></div>\n
elsif !(/_1[0-9]00/.match(image))
img_urls += <<-HTML
<div class="center"><img src="{year}/#{month}/#{cur}" alt="#{desc}"/></div>\n
# if last
img_urls += <<-HTML
<div class="center"><img src="{year}/#{month}/#{cur}" alt="#{desc}"/></div>\n
puts img_urls
filename = (0...8).map{65.+(rand(25)).chr}.join + "_imgurls_tmp.txt"
path = File.join("/tmp", filename), 'w') do |file|
file.puts img_urls
system "open -a textmate #{path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.