summaryrefslogtreecommitdiff
path: root/_plugins/image.rb
blob: 0a202caddf1cbbfb80c79de11f6edd0bd45e957f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Jekyll
  class ImageTag < Liquid::Tag

    def initialize(tag_name, parameters, tokens)
      super
      @params = {}
      parameters.scan(/(\w+)\s*=\s*"([^"]+)"/) do |key, value|
        @params[key] = value
      end
    end

    def render(context)
      environment = ENV['JEKYLL_ENV'] || 'development'

      url = @params['url']
      alt = @params['alt'] || "Link to image"

      if environment == 'ipfs'
        "<a href='#{url}'>#{alt}</a>"
      elsif alt
        "<img src='#{url}' alt='#{alt}' />"
      else
        "<img src='#{url}' />"
      end
    end
    Liquid::Template.register_tag('image', self)
  end
end