<commit_before>module Jekyll
  module Filters
    module URLFilters
      # Produces an absolute URL based on site.url and site.baseurl.
      #
      # input - the URL to make absolute.
      #
      # Returns the absolute URL as a String.
      def absolute_url(input)
        return if input.nil?
        site = @context.registers[:site]
        return relative_url(input).to_s if site.config["url"].nil?
        URI(site.config["url"] + relative_url(input)).to_s
      end

      # Produces a URL relative to the domain root based on site.baseurl.
      #
      # input - the URL to make relative to the domain root
      #
      # Returns a URL relative to the domain root as a String.
      def relative_url(input)
        return if input.nil?
        site = @context.registers[:site]
        return ensure_leading_slash(input.to_s) if site.config["baseurl"].nil?
        ensure_leading_slash( # in case the baseurl doesn't have a leading slash
          URI(
            site.config["baseurl"] + ensure_leading_slash(input.to_s)
            # in case the input doesn't have a leading slash
          ).to_s
        )
      end

      private
      def ensure_leading_slash(input)
        return input if input.nil? || input.empty? || input.start_with?("/")
        "/#{input}"
      end

    end
  end
end<commit_msg>URLFilters: Simplify ensure_leading_slash calls.<commit_after>module Jekyll
  module Filters
    module URLFilters
      # Produces an absolute URL based on site.url and site.baseurl.
      #
      # input - the URL to make absolute.
      #
      # Returns the absolute URL as a String.
      def absolute_url(input)
        return if input.nil?
        site = @context.registers[:site]
        return relative_url(input).to_s if site.config["url"].nil?
        URI(site.config["url"] + relative_url(input)).to_s
      end

      # Produces a URL relative to the domain root based on site.baseurl.
      #
      # input - the URL to make relative to the domain root
      #
      # Returns a URL relative to the domain root as a String.
      def relative_url(input)
        return if input.nil?
        site = @context.registers[:site]
        return ensure_leading_slash(input.to_s) if site.config["baseurl"].nil?
        URI(
          ensure_leading_slash(site.config["baseurl"]) + ensure_leading_slash(input.to_s)
        ).to_s
      end

      private
      def ensure_leading_slash(input)
        return input if input.nil? || input.empty? || input.start_with?("/")
        "/#{input}"
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.0895170789163722, 'fraction_numerical': 0.0, 'mean_word_length': 2.2131147540983607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '907968', 'n_tokens_mistral': 742, 'n_tokens_neox': 735, 'n_words': 229}