<commit_before>require 'nokogiri'

module Jekyll
  module LunrJsSearch
    class SearchEntry
      def self.create(page_or_post, renderer)
        case page_or_post
        when Jekyll::Page, Jekyll::Document
          date = nil
          categories = []
        else 
          if defined?(Jekyll::Post) and page_or_post.is_a?(Jekyll::Post)
            date = page_or_post.date
            categories = page_or_post.categories
          else
            raise 'Not supported'
          end
        end
        title, url = extract_title_and_url(page_or_post)
        body = renderer.render(page_or_post)

        SearchEntry.new(title, url, date, categories, body, renderer)
      end

      def self.extract_title_and_url(item)
        data = item.to_liquid
        [ data['title'], data['url'] ]
      end

      attr_reader :title, :url, :date, :categories, :body, :collection
      
      def initialize(title, url, date, categories, body, collection)
        @title, @url, @date, @categories, @body, @collection = title, url, date, categories, body, collection
      end
      
      def strip_index_suffix_from_url!
        @url.gsub!(/index\.html$/, '')
      end
      
      # remove anything that is in the stop words list from the text to be indexed
      def strip_stopwords!(stopwords, min_length)
        @body = @body.split.delete_if() do |x| 
          t = x.downcase.gsub(/[^a-z]/, '')
          t.length < min_length || stopwords.include?(t)
        end.join(' ')
      end
    end
  end
end
<commit_msg>This fixes slashdotdash/jekyll-lunr-js-search#88<commit_after>require 'nokogiri'

module Jekyll
  module LunrJsSearch
    class SearchEntry
      def self.create(page_or_post, renderer)
        case page_or_post
        when Jekyll::Page, Jekyll::Document
          if defined?(page_or_post.date)
            date = page_or_post.date
          else
            date = nil
          end
          categories = []
        else 
          if defined?(Jekyll::Post) and page_or_post.is_a?(Jekyll::Post)
            date = page_or_post.date
            categories = page_or_post.categories
          else
            raise 'Not supported'
          end
        end
        title, url = extract_title_and_url(page_or_post)
        body = renderer.render(page_or_post)

        SearchEntry.new(title, url, date, categories, body, renderer)
      end

      def self.extract_title_and_url(item)
        data = item.to_liquid
        [ data['title'], data['url'] ]
      end

      attr_reader :title, :url, :date, :categories, :body, :collection
      
      def initialize(title, url, date, categories, body, collection)
        @title, @url, @date, @categories, @body, @collection = title, url, date, categories, body, collection
      end
      
      def strip_index_suffix_from_url!
        @url.gsub!(/index\.html$/, '')
      end
      
      # remove anything that is in the stop words list from the text to be indexed
      def strip_stopwords!(stopwords, min_length)
        @body = @body.split.delete_if() do |x| 
          t = x.downcase.gsub(/[^a-z]/, '')
          t.length < min_length || stopwords.include?(t)
        end.join(' ')
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10181704260651629, 'fraction_numerical': 0.0006265664160401002, 'mean_word_length': 2.1365422396856584, 'pattern_counts': {'":': 0, '<': 5, '<?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': '239499', 'n_tokens_mistral': 1001, 'n_tokens_neox': 980, 'n_words': 240}