Skip to content

Instantly share code, notes, and snippets.

@ati
Created January 18, 2013 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ati/4568508 to your computer and use it in GitHub Desktop.
Save ati/4568508 to your computer and use it in GitHub Desktop.
using http://embed.ly with octopress
# Title: trivial hack to use embed.ly in octopress
# Authors: Alexander Nikolaev <variomap@gmail.com>
#
# Syntax {% embedly url %}
#
require 'embedly'
module Jekyll
class EmbedlyTag < Liquid::Tag
def render(context)
@markup.strip!
if @markup =~ /^https?:/
embedly = Embedly::API.new :key => context.registers[:site].config['embedly_key'],
:user_agent => 'Mozilla/5.0 (compatible; tautology2/1.0; variomap@gmail.com)'
if res = embedly.oembed(:url => @markup)
res[0].html.gsub(/width\s*=\s*"\d+"/, 'width="100%"')
else
"Error processing '#{@markup}'"
end
else
@markup
end
end
end
end
Liquid::Template.register_tag('embedly', Jekyll::EmbedlyTag)
@Mazyod
Copy link

Mazyod commented Jun 6, 2014

Holy carp, this is awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment