Class: JekyllHighlightCards::LinkcardTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
ArchiveHelper, ExpressionEvaluator, TemplateRenderer
Defined in:
lib/jekyll-highlight-cards/linkcard_tag.rb

Overview

Liquid tag for creating styled link card components

Syntax:

{% linkcard URL [TITLE] [archive:ARCHIVE_URL] %}

Parameters:

- URL (required): The URL to link to (can be Liquid expression)
- TITLE (optional): Title text to display (can be Liquid expression)
- archive:URL (optional): Explicit archive URL or "none" to opt out

Examples:

{% linkcard https://example.com %}
{% linkcard https://example.com My Link Title %}
{% linkcard {{ page.url }} {{ page.title }} %}
{% linkcard https://example.com Title archive:none %}

Instance Method Summary collapse

Methods included from TemplateRenderer

#find_template_path, #render_template, #safe_template_path

Methods included from ExpressionEvaluator

#evaluate_expression, #log_debug, #log_error, #log_info, #log_warn, #quote_wrapped?, #strip_outer_quotes, #variable_lookup?

Methods included from ArchiveHelper

#archive_enabled?, #archive_save_enabled?, #archive_url_for, #archive_user_agent

Instance Method Details

#render(context) ⇒ String

Render the linkcard tag

Parameters:

  • context (Liquid::Context)

    the Liquid rendering context

Returns:

  • (String)

    rendered HTML

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jekyll-highlight-cards/linkcard_tag.rb', line 34

def render(context)
  # Parse markup
  parsed = split_markup(@markup)

  # Resolve URL (required)
  url = resolve_url(parsed.fetch(:url), context)
  raise ArgumentError, "linkcard tag requires a URL" if url.nil? || url.empty?

  # Resolve title (optional)
  title = resolve_title(parsed[:title], context)

  # Resolve archive (optional, may auto-lookup)
  archive_url = resolve_archive(parsed[:archive], context, url)

  # Build template variables
  variables = build_template_variables(url, title, archive_url)

  # Get site from context
  site = context.registers[:site]

  # Render template
  render_template(site, "linkcard", variables)
end