├── README.md └── embedly.rb /README.md: -------------------------------------------------------------------------------- 1 | # A embed.ly client for Jekyll 2 | 3 | This is a handy embed.ly client for people that use the static-site generator 4 | jekyll. 5 | 6 | ## How to install 7 | 8 | 1. Make sure you have the _json_ and _domainatrix_ gems installed. 9 | 2. Download the `embedly.rb` file and place it in the `_plugins/` inside your 10 | Jekyll project directory. 11 | 3. Go to the embed.ly site, register an account and get your API key. 12 | 4. Add your site address to the referrer section e.g. 'localhost.com*' or 'www.mywebsite.com*' 13 | 5. Edit your `_config.yml` as described below. 14 | 6. Make use of the new `embedly`-Liquid tag somewhere on your site. 15 | E.g. `{% embedly http://soundcloud.com/mightyoaksmusic/rainier %}` 16 | 7. Compile your site. 17 | 18 | Please not that github-pages does not allow the use of plugins, if you want 19 | to make use of this plugin, you have to compile your site yourself. 20 | 21 | ## How to set up the `_config.yml` 22 | 23 | First, pass in your newly acquired API key like so: 24 | 25 | embedly: 26 | api_key: abcdefg123456780cafebabe101cat44 27 | 28 | You can further customize your embeds adding host-specific parameters. 29 | 30 | embedly: 31 | api_key: abcdefg123456780cafebabe101cat44 32 | 33 | soundcloud: 34 | color: 0066FF # SoundCloud specific parameter for colorful players 35 | width: 500px 36 | 37 | vimeo: 38 | width: 500px 39 | 40 | You can also pass along parameters to individual embeds, e.g. 41 | 42 | {% embedly http://soundcloud.com/mightyoaksmusic/rainier, color: 00FFFF %} 43 | # Linebreaks are currently not supported :-/ 44 | 45 | For a list of supported parameters, please have a look at 46 | [embed.ly’s documentation][docs] as well as the documentation for the oEmbed 47 | implementation of the specific hosts. 48 | 49 | Provider specific parameters are currently not working properly across the 50 | board. Please let me know what works and what doesn't. 51 | 52 | ## Style your embeds 53 | 54 | Your embed will be wrapped inside a `div`-tag that has classes matching the 55 | embeds type, provider as well as the generic `embed`. 56 | 57 | E.g. 58 | 59 | {% embedly http://soundcloud.com/mightyoaksmusic/rainier %} 60 | 61 | will result in 62 | 63 |
66 | 67 | [docs]: http://embed.ly/docs/endpoints/arguments 68 | -------------------------------------------------------------------------------- /embedly.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'net/https' 3 | require 'uri' 4 | require 'json' 5 | require 'domainatrix' 6 | 7 | module Jekyll 8 | class Embedly < Liquid::Tag 9 | @@EMBEDLY_PARAMETERS = ['maxwidth', 'maxheight', 'format', 'callback', 10 | 'wmode', 'allowscripts', 'nostyle', 'autoplay', 11 | 'videosrc', 'words', 'chars', 'width', 'height'] 12 | 13 | def initialize(tag_name, text, tokens) 14 | super 15 | 16 | tokens = text.split /\,\s/ 17 | @url = tokens[0] 18 | @parameters = {} 19 | 20 | tokens[1..-1].each do |arg| 21 | key, value = arg.split /:/ 22 | value ||= "1" 23 | @parameters[key.strip] = value.strip 24 | end 25 | end 26 | 27 | def render(context) 28 | @config = context.registers[:site].config['embedly'] 29 | @api_key = @config['api_key'] 30 | 31 | if @api_key.nil? 32 | raise "You must provide embed.ly api key." 33 | end 34 | 35 | embed @url 36 | end 37 | 38 | private 39 | 40 | def embed(url) 41 | provider = Domainatrix.parse(url).domain 42 | param_string = "" 43 | params = (@config[provider] or {}).merge @parameters 44 | 45 | params.each do |key, value| 46 | if @@EMBEDLY_PARAMETERS.member? key 47 | value = CGI::escape value.to_s 48 | param_string << "{key}=#{value}" 49 | else 50 | url << (url.match(/\?/) ? "&" : "?") << "#{key}=#{value}" 51 | end 52 | end 53 | 54 | encoded_url = CGI::escape url 55 | embedly_url = URI.parse "http://api.embed.ly/1/oembed?key=#{@api_key}" + 56 | "&url=#{encoded_url}#{param_string}" 57 | 58 | json_rep = JSON.parse resolve(embedly_url) 59 | 60 | compose json_rep 61 | end 62 | 63 | def compose(json_rep) 64 | type = json_rep['type'] 65 | provider = json_rep['provider_name'].downcase 66 | 67 | if type == 'photo' 68 | url = json_rep['url'] 69 | width = json_rep['width'] 70 | height = json_rep['height'] 71 | desc = CGI::escapeHTML json_rep['description'] 72 | html = "