Permalink
Browse files

Initial commit (the real one)

  • Loading branch information...
1 parent a7e3e25 commit d23df30687fabdbb42510c98f3ce5e5c702c5628 @j0k3r committed Feb 24, 2013
View
@@ -1 +0,0 @@
-_site/
View
@@ -1,4 +1,72 @@
-jekyll-flickr-photoset
-======================
+# jekyll-flickr-photoset
-A Jekyll plugin for embedding Flickr photosets
+It's a Jekyll plugin for embedding Flickr photosets in your Liquid templates.
+
+I was moving from Posterous to Jekyll and I was looking for a slideshow gallery like Posteours has. You put a simple tag with a Flickr photoset ID inside your post and it builds a slideshow gallery. So I made it: one tag generate a gallery, no more. Dead simple.
+
+## Usage
+
+ {% flickr_photoset 12345678901234567 %}
+ {% flickr_photoset 12345678901234567 "Square" "Medium 640" "Large" %}
+
+Where:
+
+- `12345678901234567` is the Flickr photoset ID (can be found in this kind of url: `http://www.flickr.com/photos/j0k/sets/72157624158475427/`)
+- `"Square"` is the size for the thumbnail image (*which also the one by default*)
+- `"Medium 640"` is the size for the displayed image (*which also the one by default*)
+- `"Large"` is the size for the opened image (*which also the one by default*)
+
+Other Flickr size can be found [here](http://www.flickr.com/services/api/flickr.photos.getSizes.html).
+
+## Requirements
+
+#### FlickRaw
+
+*Flickraw is a library to access flickr api in a simple way.*
+
+ gem install flickraw
+
+#### A Flickr API key
+
+You can obtain a Flickr API key [here](http://www.flickr.com/services/apps/create/).
+And follow instructions on [the FlickRaw page for authentication](http://hanklords.github.com/flickraw/):
+
+ - create a `flickr.rb` file with content of "Authentication" bloc code
+ - replace api key by the one previously generated on the Flickr website
+ - launch it with `ruby -rubygems flickr.rb`
+ - follow instructions
+
+Then put them inside `_config.yml` (where `flickr:` is defined on the root level):
+
+ flickr:
+ cache_dir: ./_cache/flickr
+ api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ shared_secret: xxxxxxxxxxxxxxxx
+ access_token: xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
+ access_secret: xxxxxxxxxxxxxxxx
+
+There is also an ability to generate cache. It will put all images references from each photoset. It will save **a lot of time** when you will have to regenerate all your posts. Cache are written in a yml file. Photoset ID is the file name.
+
+#### [AD Gallery](http://adgallery.codeplex.com/)
+This is the plugin used to generate the slideshow gallery, which is almost the same from Posterous. You will find references in `adgallery` folder, I put the latest version (1.2.7).
+
+So you need to load it:
+
+ <link rel="stylesheet" href="/ad-gallery/jquery.ad-gallery.css" />
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
+ <script type="text/javascript" src="/ad-gallery/jquery.ad-gallery.js?rand=302"></script>
+ <script type="text/javascript">
+ $(function() {
+ var galleries = $('.ad-gallery').adGallery({
+ loader_image: '/ad-gallery/loader.gif',
+ width: 640,
+ });
+ })
+ </script>
+
+## Inspiration
+
+I've looked inside :
+
+- [jekyll-flickr](https://github.com/cnunciato/jekyll-flickr)
+- [Integrating Flickr and Jekyll](http://www.marran.com/tech/integrating-flickr-and-jekyll/)
View
@@ -0,0 +1,6 @@
+flickr:
+ cache_dir: ./_cache/flickr
+ api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ shared_secret: xxxxxxxxxxxxxxxx
+ access_token: xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
+ access_secret: xxxxxxxxxxxxxxxx
@@ -0,0 +1,146 @@
+# Flickr Photoset Tag
+#
+# A Jekyll plug-in for embedding Flickr photoset in your Liquid templates.
+#
+# Usage:
+#
+# {% flickr_photoset 72157624158475427 %}
+# {% flickr_photoset 72157624158475427 "Square" "Medium 640" "Large" %}
+#
+# For futher information please visit: https://github.com/j0k3r/jekyll-flickr-photoset
+#
+# Author: Jeremy Benoist
+# Source: https://github.com/j0k3r/jekyll-flickr-photoset
+
+require 'flickraw'
+require 'shellwords'
+
+module Jekyll
+
+ class FlickrPhotosetTag < Liquid::Tag
+
+ def initialize(tag_name, markup, tokens)
+
+ super
+ params = Shellwords.shellwords markup
+
+ @photoset = params[0]
+ @photoThumbnail = params[1] || "Square"
+ @photoEmbeded = params[2] || "Medium 640"
+ @photoOpened = params[3] || "Large"
+
+ end
+
+ def render(context)
+
+ flickrConfig = context.registers[:site].config["flickr"]
+
+ if cache_dir = flickrConfig['cache_dir']
+ path = File.join(cache_dir, "#{@photoset}.yml")
+ if File.exist?(path)
+ photos = YAML::load(File.read(path))
+ else
+ photos = generate_photo_data(@photoset, flickrConfig)
+ File.open(path, 'w') {|f| f.print(YAML::dump(photos)) }
+ end
+ else
+ photos = generate_photo_data(@photoset, flickrConfig)
+ end
+
+ if photos.count == 1
+
+ output = "<img src=\"#{photos[0].urlEmbeded}\" title=\"#{photos[0].title}\" longdesc=\"#{photos[0].title}\" alt=\"#{photos[0].title}\" />\n"
+
+ else
+
+ output = "<div id=\"gallery-#{@photoset}\" class=\"ad-gallery\">\n"
+ output += " <div class=\"ad-image-wrapper\"></div>\n"
+ output += " <div class=\"ad-controls\"></div>\n"
+ output += " <div class=\"ad-nav\">\n"
+ output += " <div class=\"ad-thumbs\">\n"
+ output += " <ul class=\"ad-thumb-list\">\n"
+
+ photos.each_with_index do |photo, i|
+
+ output += " <li>\n"
+ # custom id needed to correctly handle multiple gallery on the same page
+ output += " <a id=\"photo-#{@photoset}-#{i}\" href=\"#{photo.urlEmbeded}\">\n"
+ output += " <img src=\"#{photo.urlThumb}\" longdesc=\"#{photo.urlOpened}\" class=\"image-#{i}\" />\n"
+ output += " </a>\n"
+ output += " </li>\n"
+
+ end
+
+ output += " </ul>\n"
+ output += " </div>\n"
+ output += " </div>\n"
+ output += "</div>\n"
+
+ end
+
+ # return content
+ output
+
+ end
+
+ def generate_photo_data(photoset, flickrConfig)
+
+ returnSet = Array.new
+
+ FlickRaw.api_key = flickrConfig['api_key']
+ FlickRaw.shared_secret = flickrConfig['shared_secret']
+ flickr.access_token = flickrConfig['access_token']
+ flickr.access_secret = flickrConfig['access_secret']
+
+ begin
+ flickr.test.login
+ rescue Exception => e
+ raise "Bad token: #{flickrConfig['access_token']}"
+ end
+
+ photos = flickr.photosets.getPhotos :photoset_id => photoset
+
+ photos.photo.each_index do | i |
+
+ title = photos.photo[i].title
+ id = photos.photo[i].id
+ urlThumb = String.new
+ urlEmbeded = String.new
+ urlOpened = String.new
+
+ sizes = flickr.photos.getSizes(:photo_id => id)
+
+ urlThumb = sizes.find {|s| s.label == @photoThumbnail }
+ urlEmbeded = sizes.find {|s| s.label == @photoEmbeded }
+ urlOpened = sizes.find {|s| s.label == @photoOpened }
+
+ photo = FlickrPhoto.new(title, urlThumb.source, urlEmbeded.source, urlOpened.source)
+ returnSet.push photo
+
+ end
+
+ # sleep a little so that you don't get in trouble for bombarding the Flickr servers
+ sleep 1
+
+ returnSet
+
+ end
+
+ end
+
+ class FlickrPhoto
+
+ attr_accessor :title, :urlThumb, :urlEmbeded, :urlOpened
+
+ def initialize(title, urlThumb, urlEmbeded, urlOpened)
+ @title = title
+ @urlThumb = urlThumb
+ @urlEmbeded = urlEmbeded
+ @urlOpened = urlOpened
+ end
+
+ end
+
+end
+
+Liquid::Template.register_tag('flickr_photoset', Jekyll::FlickrPhotosetTag)
Oops, something went wrong. Retry.

0 comments on commit d23df30

Please sign in to comment.