From 077c73b572daf3e71566d5d615e5b4ea04a91b1e Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Wed, 23 May 2012 21:21:15 +0100 Subject: [PATCH 1/4] Add rake task to create a photo post --- _rake/flickr.rake | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 _rake/flickr.rake diff --git a/_rake/flickr.rake b/_rake/flickr.rake new file mode 100644 index 0000000000..4a49fbc0df --- /dev/null +++ b/_rake/flickr.rake @@ -0,0 +1,46 @@ +# Usage: rake "flickr[http://flickr.com http://flickr.com]" +# vim: ts=2 sw=2 sts=2 + +require 'fleakr' + +Fleakr.api_key = ENV["FLICKR_API_KEY"] +Fleakr.shared_secret = ENV["FLICKR_SHARED_SECRET"] + +desc "Begin a new photo in #{CONFIG['posts']}" +task :flickr, :urls do |t, args| + abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts']) + + urls = args[:urls].split + photos = [] + urls.each_with_index do |url, index| + photos << Fleakr.resource_from_url(url) + end + + date = Time.now.strftime('%Y-%m-%d') + slug = photos[0].title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}") + if File.exist?(filename) + abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' + end + + tags = [] + photos.each do |photo| + photo.tags.each do |tag| + tags << tag.value + end + end + + open(filename, 'w') do |post| + post.puts "---" + post.puts "layout: post" + post.puts "title: '#{photos[0].title}'" + post.puts "description: '#{photos[0].description}'" + post.puts "tags: [#{tags.uniq.join(', ')}]" + post.puts "---" + post.puts "{% include JB/setup %}" + + photos.each do |photo| + post.puts "#{photo.title}" + end + end +end From aa35f8e058b43e2d52bc32d2b2b0ccf4abec0123 Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Wed, 23 May 2012 21:27:11 +0100 Subject: [PATCH 2/4] Attribution, update usage --- _rake/flickr.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/_rake/flickr.rake b/_rake/flickr.rake index 4a49fbc0df..0d650b7d41 100644 --- a/_rake/flickr.rake +++ b/_rake/flickr.rake @@ -1,4 +1,7 @@ -# Usage: rake "flickr[http://flickr.com http://flickr.com]" +# Rake task to create a photo post. +# Copyright 2012 Tom Vincent +# Usage: rake FLICKR_API_KEY="xxx" FLICKR_SHARED_SECRET="xxx" \ +# "flickr[http://www.flickr.com/photos/tlvince/6467485431 ...]" # vim: ts=2 sw=2 sts=2 require 'fleakr' From c1acd7de176d2c38fd16e23b60f21f43f544cb85 Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Wed, 23 May 2012 22:17:49 +0100 Subject: [PATCH 3/4] Parse date from photo, link back to flickr --- _rake/flickr.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_rake/flickr.rake b/_rake/flickr.rake index 0d650b7d41..fae5343263 100644 --- a/_rake/flickr.rake +++ b/_rake/flickr.rake @@ -19,7 +19,7 @@ task :flickr, :urls do |t, args| photos << Fleakr.resource_from_url(url) end - date = Time.now.strftime('%Y-%m-%d') + date = Time.parse(photos[0].taken).strftime('%Y-%m-%d') slug = photos[0].title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}") if File.exist?(filename) @@ -43,7 +43,7 @@ task :flickr, :urls do |t, args| post.puts "{% include JB/setup %}" photos.each do |photo| - post.puts "#{photo.title}" + post.puts "#{photo.title}" end end end From 75dc382cfbcae1936fed18e3e27bb21f695112d7 Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Sun, 27 May 2012 20:40:53 +0100 Subject: [PATCH 4/4] Add ignore tag function --- _rake/flickr.rake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/_rake/flickr.rake b/_rake/flickr.rake index fae5343263..1defd4d25f 100644 --- a/_rake/flickr.rake +++ b/_rake/flickr.rake @@ -1,7 +1,8 @@ # Rake task to create a photo post. # Copyright 2012 Tom Vincent # Usage: rake FLICKR_API_KEY="xxx" FLICKR_SHARED_SECRET="xxx" \ -# "flickr[http://www.flickr.com/photos/tlvince/6467485431 ...]" +# "flickr[http://www.flickr.com/photos/tlvince/6467485431 ...]" \ +# [ignore="tag1,tag2] # vim: ts=2 sw=2 sts=2 require 'fleakr' @@ -33,6 +34,10 @@ task :flickr, :urls do |t, args| end end + if ENV["ignore"] + tags -= ENV["ignore"].split(",") + end + open(filename, 'w') do |post| post.puts "---" post.puts "layout: post"