<commit_before>require 'active_support'
require 'active_support/core_ext/hash/keys'

# Got this idea from: https://stackoverflow.com/questions/8126802/when-testing-with-rspec-where-to-put-common-test-utility-methods
module PostHelpers
  def create_post(post_name, title:'Blah', body:'Super blah, foo blah.', is_public: false, created_at: nil, wordpress: nil)
    piece_path = File.join(Everything::Blog::Source.absolute_path, post_name)
    piece = Everything::Piece.new(piece_path)

    FileUtils.mkdir_p(piece.full_path)

    File.open(piece.content.file_path, 'w') do |f|
      f.write("# #{title}\n\n#{body}")
    end

    metadata = {}.tap do |h|
      h['public'] = is_public || false
      h['wordpress'] = wordpress.deep_stringify_keys if wordpress
      h['created_at'] =
        if created_at
          created_at
        elsif !wordpress
          Time.now.to_i
        end
    end

    File.open(piece.metadata.file_path, 'w') do |f|
      f.write(metadata.to_yaml)
    end
  end

  def create_media_for_post(post_name)
    piece_path = File.join(Everything::Blog::Source.absolute_path, post_name)<commit_msg>Change to created_on in posts helper<commit_after>require 'date'
require 'active_support'
require 'active_support/core_ext/hash/keys'

# Got this idea from: https://stackoverflow.com/questions/8126802/when-testing-with-rspec-where-to-put-common-test-utility-methods
module PostHelpers
  def create_post(post_name, title:'Blah', body:'Super blah, foo blah.', is_public: false, created_on: nil)
    piece_path = File.join(Everything::Blog::Source.absolute_path, post_name)
    piece = Everything::Piece.new(piece_path)

    FileUtils.mkdir_p(piece.full_path)

    File.open(piece.content.file_path, 'w') do |f|
      f.write("# #{title}\n\n#{body}")
    end

    metadata = {}.tap do |h|
      h['public'] = is_public || false
      h['created_on'] =
        if created_on
          created_on
        else
          Time.now.to_date.iso8601
        end
    end

    File.open(piece.metadata.file_path, 'w') do |f|
      f.write(metadata.to_yaml)
    end
  end

  def create_media_for_post(post_name)
    piece_path = File.join(Everything::Blog::Source.absolute_path, post_name)
{'fraction_non_alphanumeric': 0.12835685025034138, 'fraction_numerical': 0.008192990441511151, 'mean_word_length': 3.541322314049587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2461836', 'n_tokens_mistral': 773, 'n_tokens_neox': 737, 'n_words': 137}