28 lines
No EOL
911 B
Ruby
28 lines
No EOL
911 B
Ruby
module Jekyll
|
|
class EmojiTag < Liquid::Tag
|
|
def initialize(tag_name, text, tokens)
|
|
super
|
|
@text = text.strip
|
|
end
|
|
|
|
def render(context)
|
|
# Load the emoji data from the _data/emoji.yml file
|
|
emojis = context.registers[:site].data['emoji']
|
|
#puts emojis.inspect # Debugging line to output the emoji data to the console
|
|
|
|
# Search for the emoji with the name matching @text
|
|
emoji = emojis.find { |e| e['shortcode'] == @text }
|
|
|
|
if emoji
|
|
# Construct the img HTML tag if found
|
|
"<img src='/img/emoji/#{emoji['imgurl']}' alt='#{emoji['shortcode']}' class='emoji'>"
|
|
else
|
|
# Return a default alt text if not found
|
|
"<span class='emoji-not-found'>#{@text}</span>"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# Register the custom tag
|
|
Liquid::Template.register_tag('emoji', Jekyll::EmojiTag) |