From 2dd32393c0744e758358b794446473c57afa0714 Mon Sep 17 00:00:00 2001
From: uvok cheetah
Date: Sun, 6 Oct 2024 12:01:26 +0200
Subject: Improve image tag
Add linked image.
Use consistent parameter names.
---
_plugins/image.rb | 50 ++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 8 deletions(-)
(limited to '_plugins/image.rb')
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
+ ""
+ else
+ ""
+ 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'
- "#{alt}"
- elsif alt
- ""
+ 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
--
cgit v1.2.3