Module: Jekyll::LinkFilter

Defined in:
lib/jekyll-link-url-filter.rb

Instance Method Summary collapse

Instance Method Details

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jekyll-link-url-filter.rb', line 3

def link_url(input)
  # This is taken from https://github.com/jekyll/jekyll/blob/d971e39b4feca9c8d2e8c7e954aa78713ce4eb90/lib/jekyll/tags/link.rb
  # Tweaked to work via filters.
  site = @context.registers[:site]
  relative_path = Liquid::Template.parse(input).render(@context)

  site.each_site_file do |item|
    return relative_url(item) if item.relative_path == relative_path
    # This takes care of the case for static files that have a leading /
    return relative_url(item) if item.relative_path == "/#{relative_path}"
  end

  raise ArgumentError, "  Could not find document '\#{relative_path}' in filter '\#{__method__}'.\n  Make sure the document exists and the path is correct.\n  MSG\nend\n"