Skip to content

Commit

Permalink
added alert plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Jul 29, 2024
1 parent 7364fef commit 9ba8817
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions _plugins/alert.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Jekyll
# {% alert %} Some info message {% endalert %}
# {% alert info|warning|danger %} Well done! You successfully read this important alert message. {% endalert %}

class AlertBlock < Liquid::Block

def initialize(tag_name, markup, tokens)
@style = "info"
@icon = "message-rounded-detail"
if /(?<style>[^\s]+)/i =~ markup
if style == 'warning'
@icon = 'alarm-exclamation'
@style = style
elsif style == 'danger'
@icon = 'info-circle'
@style = style
end
end
super
end

def render(context)
site = context.registers[:site]
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
output = converter.convert(super(context))
return "<div class=\"alert alert-#{@style} d-flex\" role=\"alert\"><i class=\"bx bx-#{@icon} lead me-3\"></i>#{output}</div>"
end
end

end

Liquid::Template.register_tag('alert', Jekyll::AlertBlock)

0 comments on commit 9ba8817

Please sign in to comment.