Skip to content

Instantly share code, notes, and snippets.

@nurinamu
Created September 7, 2014 23:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nurinamu/4ccf7197a1bdfb0d7079 to your computer and use it in GitHub Desktop.
Save nurinamu/4ccf7197a1bdfb0d7079 to your computer and use it in GitHub Desktop.
jekyll plugin for custom size img tag.
module Jekyll
class RenderImgTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@url , *@val= text.split(/ /)
if @val.length > 0
@width , *@height = @val[0].split(/x/)
end
@img_style = "width:#{@width}px;"
if @height.length > 0
@img_style = @img_style + "height:#{@height[0]}px;"
end
end
def render(context)
"<img src=\"#{@url}\" style=\"#{@img_style}\">"
end
end
end
Liquid::Template.register_tag('img', Jekyll::RenderImgTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment