<commit_before>require 'ostruct'
require 'digest/md5'

module MiddlemanCasperHelpers
  def page_title
    title = blog_settings.name.dup
    if is_tag_page?
      title << ": #{current_resource.metadata[:locals]['tagname']}"
    elsif current_page.data.title
      title << ": #{current_page.data.title}"
    elsif is_blog_article?
      title << ": #{current_article.title}"
    end
    title
  end

  def page_description
    if is_blog_article?
      body = strip_tags(current_article.body).gsub(/\s+/, ' ')
      truncate(body, length: 147)
    else
      blog_settings.description
    end
  end

  def page_class
    if is_blog_article? || current_page.data.layout == 'page'
      'post-template'
    elsif current_resource.metadata[:locals]['page_number'].to_i > 1
      'archive-template'
    else
      'archive-template'
    end
  end

  def summary(article)
    summary_length = article.blog_options[:summary_length]
    strip_tags(article.summary(summary_length, ''))
  end

  def read_next_summary(article, words)
    body = strip_tags(article.body)
    truncate_words(body, length: words, omission: '')
  end

  def blog_author
    OpenStruct.new(casper[:author])
  end

  def blog_settings
    OpenStruct.new(casper[:blog])
  end
  def theme(page = current_page)
    page.data.theme || 'default'
  end
  def navigation
    casper[:navigation]
  end
  def image_cover(page = current_page)
    if (src = page.data.cover).present?
      image_tag src, resize_to: '700x'
    end
  end
  def is_tag_page?
    current_resource.metadata[:locals]['page_type'] == 'tag'
  end
  def tags?(article = current_article)
    article.tags.present?
  end
  def tags(article = current_article, separator = ', ')
    capture_haml do
      article.tags.each do |tag|
        haml_tag(:a, tag, href: tag_path(tag))
        haml_concat(separator) unless article.tags.last == tag
      end
    end.gsub("\n", '')
  end

  def current_article_url
    URI.join(blog_settings.url, current_article.url)
  end

  def cover_url(page = current_page)
    if (src = page.data.cover).present?
      image_path(src)
    end
  end
  def cover(page = current_page)
    if (src = page.data.cover).present?
      { style: "background-image: url(#{image_path(src)})" }
    else
      { class: 'no-cover' }
    end
  end
  def cover?(page = current_page)
    page.data.cover.present?
  end

  def gravatar(size = 68)
    md5 = Digest::MD5.hexdigest(blog_author.gravatar_email.downcase)
    "https://www.gravatar.com/avatar/#{md5}?size=#{size}"
  end
  def gravatar?
    blog_author.gravatar_email.present?
  end
  def localized_path(path, language=nil)
    language ||= I18n.locale

    if language.to_s == I18n.default_locale.to_s
      path = "/#{path}"
    else
      path = "/#{language}/#{path}";
    end
  end
  def twitter_url
    "https://twitter.com/share?text=#{current_article.title}" \
      "&amp;url=#{current_article_url}"
  end
  def facebook_url
    "https://www.facebook.com/sharer/sharer.php?u=#{current_article_url}"
  end
  def google_plus_url
    "https://plus.google.com/share?url=#{current_article_url}"
  end

  def feed_path
    if I18n.locale == I18n.default_locale
      "/feed.xml"
    else
      "/#{I18n.locale}/feed.xml"
    end
  end

  def home_path(language=nil)
    language ||= I18n.locale
    if language.to_s == I18n.default_locale.to_s
      "/"
    else
      "/#{language}/"
    end
    
  end
  def author_path
    if I18n.locale == I18n.default_locale
      "/author/#{blog_author.name.parameterize}/"
    else
      "/#{I18n.locale}/author/#{blog_author.name.parameterize}/"
    end
  end<commit_msg>add space<commit_after>require 'ostruct'
require 'digest/md5'

module MiddlemanCasperHelpers
  def page_title
    title = blog_settings.name.dup
    if is_tag_page?
      title << ": #{current_resource.metadata[:locals]['tagname']}"
    elsif current_page.data.title
      title << ": #{current_page.data.title}"
    elsif is_blog_article?
      title << ": #{current_article.title}"
    end
    title
  end

  def page_description
    if is_blog_article?
      body = strip_tags(current_article.body).gsub(/\s+/, ' ')
      truncate(body, length: 147)
    else
      blog_settings.description
    end
  end

  def page_class
    if is_blog_article? || current_page.data.layout == 'page'
      'post-template'
    elsif current_resource.metadata[:locals]['page_number'].to_i > 1
      'archive-template'
    else
      'archive-template'
    end
  end

  def summary(article)
    summary_length = article.blog_options[:summary_length]
    strip_tags(article.summary(summary_length, ''))
  end

  def read_next_summary(article, words)
    body = strip_tags(article.body)
    truncate_words(body, length: words, omission: '')
  end

  def blog_author
    OpenStruct.new(casper[:author])
  end

  def blog_settings
    OpenStruct.new(casper[:blog])
  end
  def theme(page = current_page)
    page.data.theme || 'default'
  end
  def navigation
    casper[:navigation]
  end
  def image_cover(page = current_page)
    if (src = page.data.cover).present?
      image_tag src, resize_to: '700x'
    end
  end
  def is_tag_page?
    current_resource.metadata[:locals]['page_type'] == 'tag'
  end
  def tags?(article = current_article)
    article.tags.present?
  end
  def tags(article = current_article, separator = ', ')
    capture_haml do
      article.tags.each do |tag|
        haml_tag(:a, tag, href: tag_path(tag))
        haml_concat(separator) unless article.tags.last == tag
      end
    end.gsub("\n", '')
  end

  def current_article_url
    URI.join(blog_settings.url, current_article.url)
  end

  def cover_url(page = current_page)
    if (src = page.data.cover).present?
      image_path(src)
    end
  end
  def cover(page = current_page)
    if (src = page.data.cover).present?
      { style: "background-image: url(#{image_path(src)})" }
    else
      { class: 'no-cover' }
    end
  end
  def cover?(page = current_page)
    page.data.cover.present?
  end

  def gravatar(size = 68)
    md5 = Digest::MD5.hexdigest(blog_author.gravatar_email.downcase)
    "https://www.gravatar.com/avatar/#{md5}?size=#{size}"
  end
  def gravatar?
    blog_author.gravatar_email.present?
  end
  def localized_path(path, language=nil)
    language ||= I18n.locale

    if language.to_s == I18n.default_locale.to_s
      path = "/#{path}"
    else
      path = "/#{language}/#{path}";
    end
  end
  def twitter_url
    "https://twitter.com/share?text=#{current_article.title}" \
      "&amp;url=#{current_article_url}"
  end
  def facebook_url
    "https://www.facebook.com/sharer/sharer.php?u=#{current_article_url}"
  end
  def google_plus_url
    "https://plus.google.com/share?url=#{current_article_url}"
  end

  def feed_path
    if I18n.locale == I18n.default_locale
      "/feed.xml"
    else
      "/#{I18n.locale}/feed.xml"
    end
  end

  def home_path(language=nil)
    language ||= I18n.locale
    if language.to_s == I18n.default_locale.to_s
      "/"
    else
      "/#{language}/"
    end
  end
  
  def author_path
    if I18n.locale == I18n.default_locale
      "/author/#{blog_author.name.parameterize}/"
    else
      "/#{I18n.locale}/author/#{blog_author.name.parameterize}/"
    end
  end
{'fraction_non_alphanumeric': 0.1269358407079646, 'fraction_numerical': 0.009126106194690266, 'mean_word_length': 3.0228031145717464, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, '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': '3934308', 'n_tokens_mistral': 2576, 'n_tokens_neox': 2509, 'n_words': 464}