Sha256: c2c9f6218913db774e0fb3f2dbd1fd61a38d83584915d08a39021ae19b39314c

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Jekyll
  module Tags
    class Link < Liquid::Tag
      include Jekyll::Filters::URLFilters

      class << self
        def tag_name
          name.split("::").last.downcase
        end
      end

      def initialize(tag_name, relative_path, tokens)
        super

        @relative_path = relative_path.strip
      end

      def render(context)
        @context = context
        site = context.registers[:site]
        relative_path = Liquid::Template.parse(@relative_path).render(context)
        relative_path_with_leading_slash = PathManager.join("", relative_path)

        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_with_leading_slash
        end

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

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

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

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
jekyll-4.4.1 lib/jekyll/tags/link.rb
jekyll-4.4.0 lib/jekyll/tags/link.rb
jekyll-4.3.4 lib/jekyll/tags/link.rb
jekyll-4.3.3 lib/jekyll/tags/link.rb
jekyll-4.3.2 lib/jekyll/tags/link.rb
jekyll-4.3.1 lib/jekyll/tags/link.rb
jekyll-4.3.0 lib/jekyll/tags/link.rb
jekyll-4.2.2 lib/jekyll/tags/link.rb
jekyll-4.2.0 lib/jekyll/tags/link.rb
jekyll-highlight-param-0.0.2 lib/jekyll/tags/link.rb