diff options
author | uvok cheetah | 2024-10-06 12:01:26 +0200 |
---|---|---|
committer | uvok cheetah | 2024-10-06 12:01:26 +0200 |
commit | 2dd32393c0744e758358b794446473c57afa0714 (patch) | |
tree | 977b1028fbaf019b6b038d5529691c5ecb6f5f59 /_plugins/image.rb | |
parent | 3614141c8ec5ee97c06e41d516b22ab6707f9f89 (diff) |
Improve image tag
Add linked image.
Use consistent parameter names.
Diffstat (limited to '_plugins/image.rb')
-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 |