<commit_before>class Collection < Cmless
  ROOT = File.expand_path('../views/collections', File.dirname(__FILE__))
  attr_reader :head_html
  attr_reader :short_html
  attr_reader :medium_html
  attr_reader :long_html
  attr_reader :links_html
  attr_reader :grid_html

  private
  
  def img_src(alt)
    Nokogiri::HTML(head_html).xpath("//img[@alt='#{alt}']/@src").first.tap do |optional|
      if optional
        return optional.text
      else
        return nil
      end
    end
  end
  
  public
  
  def thumb_src
    @thumb_src ||= img_src('thumb')
  end
  
  def splash_src
    @splash_src ||= img_src('splash')
  end
  
  def logo_src
    @logo_src ||= img_src('logo')
  end
  
  def url
    @url ||= '/collections/' + path
  end
  
  
  def grid_items
    @grid_items ||= begin
      Nokogiri::HTML(grid_html).xpath('//li').map do |li|
        title, short_html = li.text.split(/\s*\|\s*/).map(&:strip)
        OpenStruct.new(
          title: title, 
          short_html: short_html, 
          thumb_src: li.xpath('img/@src'),
          url: li.xpath('a/@href')
        )
      end
    end
  end
  
end<commit_msg>Linebreak in list puts extra <p> INSIDE <li>... so we need a .// to search subtree. Texts also include pipe, so handle that.<commit_after>class Collection < Cmless
  ROOT = File.expand_path('../views/collections', File.dirname(__FILE__))
  attr_reader :head_html
  attr_reader :short_html
  attr_reader :medium_html
  attr_reader :long_html
  attr_reader :links_html
  attr_reader :grid_html

  private
  
  def img_src(alt)
    Nokogiri::HTML(head_html).xpath("//img[@alt='#{alt}']/@src").first.tap do |optional|
      if optional
        return optional.text
      else
        return nil
      end
    end
  end
  
  public
  
  def thumb_src
    @thumb_src ||= img_src('thumb')
  end
  
  def splash_src
    @splash_src ||= img_src('splash')
  end
  
  def logo_src
    @logo_src ||= img_src('logo')
  end
  
  def url
    @url ||= '/collections/' + path
  end
  
  
  def grid_items
    @grid_items ||= begin
      Nokogiri::HTML(grid_html).xpath('//li').map do |li|
        texts = li.text.split(/\s*\|\s*/).map(&:strip)
        title = texts.shift
        short_html = texts.join(' | ')
        OpenStruct.new(
          title: title, 
          short_html: short_html, 
          thumb_src: li.xpath('.//img/@src').text,
          url: li.xpath('.//a/@href').text
        )
      end
    end
  end
  
end
{'fraction_non_alphanumeric': 0.13226863226863228, 'fraction_numerical': 0.0, 'mean_word_length': 2.337431693989071, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3708747', 'n_tokens_mistral': 884, 'n_tokens_neox': 867, 'n_words': 181}