diff options
-rw-r--r-- | _plugins/image.rb | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/_plugins/image.rb b/_plugins/image.rb index 0a202ca..64a944f 100644 --- a/_plugins/image.rb +++ b/_plugins/image.rb @@ -1,28 +1,62 @@ module Jekyll - class ImageTag < Liquid::Tag - + class ImageTagBase < Liquid::Tag def initialize(tag_name, parameters, tokens) super @params = {} parameters.scan(/(\w+)\s*=\s*"([^"]+)"/) do |key, value| @params[key] = value end + + if not @params['img'] + raise StandardError.new "Must provide image" + end end + def image_tag + img = @params['img'] + alt = @params['alt'] + + if alt + "<img src='#{img}' alt='#{alt}' />" + else + "<img src='#{img}' />" + end + end + + end + + class ImageTag < ImageTagBase def render(context) environment = ENV['JEKYLL_ENV'] || 'development' - url = @params['url'] - alt = @params['alt'] || "Link to image" + img = @params['img'] + alt = @params['alt'] if environment == 'ipfs' - "<a href='#{url}'>#{alt}</a>" - elsif alt - "<img src='#{url}' alt='#{alt}' />" + alt = alt || "Link to image" + "<a href='#{img}'>#{alt}</a>" else - "<img src='#{url}' />" + image_tag end end Liquid::Template.register_tag('image', self) end + + class LinkedImageTag < ImageTagBase + def render(context) + environment = ENV['JEKYLL_ENV'] || 'development' + + img = @params['img'] + url = @params['url'] || img + alt = @params['alt'] + + if environment == 'ipfs' + alt = alt || "Link to image" + "<a href='#{url}'>#{alt}</a>" + else + "<a href='#{url}'>#{image_tag}</a>" + end + end + Liquid::Template.register_tag('linked_image', self) + end end |