module Jekyll
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
""
else
""
end
end
end
class ImageTag < ImageTagBase
def render(context)
environment = ENV['JEKYLL_ENV'] || 'development'
img = @params['img']
alt = @params['alt']
if environment == 'ipfs'
alt = alt || "Link to image"
"#{alt}"
else
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"
"#{alt}"
else
"#{image_tag}"
end
end
Liquid::Template.register_tag('linked_image', self)
end
end