├── README.md └── _plugins └── flickr_set.rb /README.md: -------------------------------------------------------------------------------- 1 | # Flickr Set Tag 2 | 3 | Generates image galleries from a Flickr set. 4 | 5 | Usage: 6 | 7 | {% flickr_set flickr_set_id %} 8 | 9 | Example: 10 | 11 | {% flickr_set 72157625102245887 %} 12 | 13 | Default Configuration (override in _config.yml): 14 | 15 | flickr_set: 16 | gallery_tag: 'p' 17 | gallery_class: 'gallery' 18 | a_href: nil 19 | a_target: '_blank' 20 | image_rel: '' 21 | image_size: 's' 22 | api_key: '' 23 | 24 | By default, thumbnails are linked to their corresponding Flickr page. 25 | If you override a_href with a size ('s', 'm', etc), the thumbnail will 26 | link to that size image. This is useful in combination with the image_rel 27 | parameter and a lightbox gallery. 28 | 29 | You must provide an API Key in order to query Flickr. It must be configured in _config.yml. -------------------------------------------------------------------------------- /_plugins/flickr_set.rb: -------------------------------------------------------------------------------- 1 | # Flickr Set Tag. 2 | # 3 | # Generates image galleries from a Flickr set. 4 | # 5 | # Usage: 6 | # 7 | # {% flickr_set flickr_set_id %} 8 | # 9 | # Example: 10 | # 11 | # {% flickr_set 72157625102245887 %} 12 | # 13 | # Default Configuration (override in _config.yml): 14 | # 15 | # flickr_set: 16 | # gallery_tag: 'p' 17 | # gallery_class: 'gallery' 18 | # a_href: nil 19 | # a_target: '_blank' 20 | # image_rel: '' 21 | # image_size: 's' 22 | # api_key: '' 23 | # 24 | # By default, thumbnails are linked to their corresponding Flickr page. 25 | # If you override a_href with a size ('s', 'm', etc), the thumbnail will 26 | # link to that size image. This is useful in combination with the image_rel 27 | # parameter and a lightbox gallery. 28 | # 29 | # You must provide an API Key in order to query Flickr. It must be configured in _config.yml. 30 | # 31 | # Author: Thomas Mango 32 | # Site: http://thomasmango.com 33 | # Plugin Source: http://github.com/tsmango/jekyll_flickr_set_tag 34 | # Site Source: http://github.com/tsmango/thomasmango.com 35 | # Plugin License: MIT 36 | 37 | require 'net/https' 38 | require 'uri' 39 | require 'json' 40 | 41 | module Jekyll 42 | class FlickrSetTag < Liquid::Tag 43 | def initialize(tag_name, config, token) 44 | super 45 | 46 | @set = config.strip 47 | 48 | @config = Jekyll.configuration({})['flickr_set'] || {} 49 | 50 | @config['gallery_tag'] ||= 'p' 51 | @config['gallery_class'] ||= 'gallery' 52 | @config['a_href'] ||= nil 53 | @config['a_target'] ||= '_blank' 54 | @config['image_rel'] ||= '' 55 | @config['image_size'] ||= 's' 56 | @config['api_key'] ||= '' 57 | end 58 | 59 | def render(context) 60 | html = "<#{@config['gallery_tag']} class=\"#{@config['gallery_class']}\">" 61 | 62 | photos.each do |photo| 63 | html << "" 64 | html << " " 65 | html << "" 66 | end 67 | 68 | html << "" 69 | 70 | return html 71 | end 72 | 73 | def photos 74 | @photos = Array.new 75 | 76 | JSON.parse(json)['photoset']['photo'].each do |item| 77 | @photos << FlickrPhoto.new(item['title'], item['id'], item['secret'], item['server'], item['farm'], @config['image_size']) 78 | end 79 | 80 | @photos.sort 81 | end 82 | 83 | def json 84 | uri = URI.parse("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&photoset_id=#{@set}&api_key=#{@config['api_key']}&format=json&nojsoncallback=1") 85 | http = Net::HTTP.new(uri.host, uri.port) 86 | return http.request(Net::HTTP::Get.new(uri.request_uri)).body 87 | end 88 | end 89 | 90 | class FlickrPhoto 91 | 92 | def initialize(title, id, secret, server, farm, thumbnail_size) 93 | @title = title 94 | @url = "http://farm#{farm}.staticflickr.com/#{server}/#{id}_#{secret}.jpg" 95 | @thumbnail_url = url.gsub(/\.jpg/i, "_#{thumbnail_size}.jpg") 96 | @thumbnail_size = thumbnail_size 97 | end 98 | 99 | def title 100 | return @title 101 | end 102 | 103 | def url(size_override = nil) 104 | return (size_override ? @thumbnail_url.gsub(/_#{@thumbnail_size}.jpg/i, "_#{size_override}.jpg") : @url) 105 | end 106 | 107 | def thumbnail_url 108 | return @thumbnail_url 109 | end 110 | 111 | def <=>(photo) 112 | @title <=> photo.title 113 | end 114 | end 115 | end 116 | 117 | Liquid::Template.register_tag('flickr_set', Jekyll::FlickrSetTag) 118 | --------------------------------------------------------------------------------