Class: Jekyll::PostCard::PostTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-post-card/post_tag.rb

Overview

Liquid tag for rendering post cards Usage:

{% post_card /2024/01/01/my-post %}
{% post_card https://example.com/article %}
{% post_card /my-post variant:compact %}

Constant Summary collapse

VALID_VARIANTS =
%w[default compact vertical].freeze
EXTERNAL_URL_PATTERN =
%r{^https?://}i

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ PostTag

Returns a new instance of PostTag.



14
15
16
17
# File 'lib/jekyll-post-card/post_tag.rb', line 14

def initialize(tag_name, markup, tokens)
  super
  parse_arguments(markup.strip)
end

Instance Method Details

#render(context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jekyll-post-card/post_tag.rb', line 19

def render(context)
  site = context.registers[:site]

  begin
    if external_url?
      render_external_card(context)
    else
      render_internal_card(site, context)
    end
  rescue StandardError => e
    render_error_card("Error rendering card: #{e.message}")
  end
end