webbed-site/_plugins/emote_shortcode.rb

28 lines
911 B
Ruby
Raw Normal View History

2025-01-06 12:22:24 -06:00
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)