class Jekyll::Tags::IconTag

Our {% icon X %} tag

Public Class Methods

Calls superclass method
# File _plugins/jekyll-icon-tag.rb, line 8
def initialize(tag_name, text, tokens)
  super
  parts = text.strip.split
  @text = parts[0]
  @aria = true
  return unless parts[1] == 'aria=false'

  @aria = false
end

Public Instance Methods

# File _plugins/jekyll-icon-tag.rb, line 69
def get_config(context)
  context.registers[:site].config['icon-tag']
end

icon - Include an icon from our _config.yml into your tutorial

Examples:

{% icon email %}
{% icon galaxy-history %}
# File _plugins/jekyll-icon-tag.rb, line 63
def render(context)
  cfg = get_config(context)
  icon = cfg[@text] || ''
  render_for_text(icon)
end

This function renders the icon tag Params:

icon

The icon to render

+@area+

Whether to add aria-hidden

+@text+

The text to add to the icon

Returns: The HTML for the icon Note: The icon text label is wrapped in a span with class

"visually-hidden" to make it accessible to screen readers.

Example:

{% icon fa fa-github %}
=> <i class="fa fa-github" aria-hidden="true"></i>
{% icon fa fa-github aria=false %}
=> <i class="fa fa-github"></i>
# File _plugins/jekyll-icon-tag.rb, line 35
def render_for_text(icon)
  if icon.empty?
    raise SyntaxError, "No icon defined for: '#{@text}'. Please define it in `_config.yml` (under `icon-tag:`)."
  end

  if icon.start_with?('fa')
    if @aria
      %(<i class="#{icon}" aria-hidden="true"></i><span class="visually-hidden">#{@text}</span>)
    else
      %(<i class="#{icon}" aria-hidden="true"></i>)
    end
  elsif icon.start_with?('ai')
    if @aria
      %(<i class="ai #{icon}" aria-hidden="true"></i><span class="visually-hidden">#{@text}</span>)
    else
      %(<i class="ai #{icon}" aria-hidden="true"></i>)
    end
  end
end