Sha256: c59d7933d15339b45eefc3dbf83ed66b3f3251f9bfffe682045ac75a46509159

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

module Jekyll
  module Tags
    class Link < Liquid::Tag
      class << self
        def tag_name
          self.name.split("::").last.downcase
        end
      end

      def initialize(tag_name, relative_path, tokens)
        super

        @relative_path = relative_path.strip
      end

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

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

        raise ArgumentError, <<eos
Could not find document '#{@relative_path}' in tag '#{self.class.tag_name}'.

Make sure the document exists and the path is correct.
eos
      end
    end
  end
end

Liquid::Template.register_tag(Jekyll::Tags::Link.tag_name, Jekyll::Tags::Link)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-3.6.0 lib/jekyll/tags/link.rb
jekyll-3.6.0.pre.beta1 lib/jekyll/tags/link.rb