Class: JekyllAlgoliaLink

Inherits:
Jekyll::Tags::Link
  • Object
show all
Defined in:
lib/jekyll/algolia/overwrites/jekyll-tags-link.rb

Overview

The default ‘link` tag allow to link to a specific page, using its relative path. Because we might not be indexing the destination of the link, we might not have the representation of the page in our data. If that happens, the `link` tag fails.

To fix that we’ll overwrite the default ‘link` tag to loop over a backup copy of the original files (before we clean it for indexing)

github.com/algolia/jekyll-algolia/issues/62

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jekyll/algolia/overwrites/jekyll-tags-link.rb', line 13

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

  original_files[:pages].each do |page|
    return page.url if page.relative_path == @relative_path
  end

  original_files[:collections].each_value do |collection|
    collection.docs.each do |item|
      return item.url if item.relative_path == @relative_path
    end
  end

  original_files[:static_files].each do |asset|
    return asset.url if asset.relative_path == @relative_path
    return asset.url if asset.relative_path == "/#{@relative_path}"
  end

  '/'
end