Created
January 18, 2013 21:04
-
-
Save ati/4568508 to your computer and use it in GitHub Desktop.
using http://embed.ly with octopress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Holy carp, this is awesome