<commit_before>require 'html-proofer'
require 'mail_to_awesome'
require 'rake'
require 'w3c_validators'
require 'colorize'

# http://stackoverflow.com/a/11320444/300224
Rake::TaskManager.record_task_metadata = true

################################################################################
## Your Rakefile can override these variables
################################################################################
@source_dir = '.'            # Editable source code, preferrably in git repo
@build_dir = 'BUILD'         # Built HTML code
@backup_dir = 'BACKUPS'      # Local home for backups of remote server
@remote_dir = '/dev/null'    # Your remote server, use rsync format
@backup_targets = {}         # Hash from local name to remote directory
                             # uses rsync naming format, example:
                             # {
                             #   'www' => 'hor<EMAIL>@172.16.11.23:/www',
                             #   'logs' => '<EMAIL>@172.16.11.23:/logs'
                             # }
@build_excludes = [          # Files you do NOT want copied from SOURCE to BUILD
  'Rakefile',                # use rsync format
  'Gemfile',
  'Gemfile.lock',
  '.bundle',
  '.git',
  '.gitignore',
  '.travis.yml',
  'vendor',
  '/tmp'
]

def create_build_dir (build_dir=@build_dir)
  FileUtils.mkdir_p build_dir
  #TODO: output if directory did not exist and we created it
end

namespace :git do
  def source_dir_is_git?
    return false if !File.directory?(@source_dir)
    return system("cd #{@source_dir} && git rev-parse --git-dir > /dev/null 2> /dev/null")
  end

  desc "Incorporate changes from the remote repository into the current branch"
  task :pull do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    puts '⚡️ Pulling git'.blue
    sh "cd '#{@source_dir}'; git pull"
    puts '✅ Pulled'.green
  end

  desc "Displays paths that have differences between the index file and the current HEAD commit"
  task :status do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    puts 'Here are differences between git\'s index file and the current HEAD commit'.blue
    sh "cd #{@source_dir} && git status --short"
  end

  desc "Print the modified date for all files under source control"
  task :stale_report do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    puts '📋 Here is the modification date for each file'.blue
    sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}", noop: true
    puts 'Modified   File'.blue
    sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}", verbose: false
  end

  desc "Save the commit hash to VERSION in the build directory"
  task :save_version do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    hash = `cd #{@source_dir} && git rev-parse HEAD`.chomp
    local_changes = `git diff --shortstat`.chomp.length
    File.write(@build_dir + '/VERSION', local_changes ? "#{hash}*" : "#{hash}")
    puts 'Saved git version to VERSION file'.green
  end
end

namespace :jekyll do<commit_msg>Wrong git version issue is fixed, this commit fixes #13<commit_after>require 'html-proofer'
require 'mail_to_awesome'
require 'rake'
require 'w3c_validators'
require 'colorize'

# http://stackoverflow.com/a/11320444/300224
Rake::TaskManager.record_task_metadata = true

################################################################################
## Your Rakefile can override these variables
################################################################################
@source_dir = '.'            # Editable source code, preferrably in git repo
@build_dir = 'BUILD'         # Built HTML code
@backup_dir = 'BACKUPS'      # Local home for backups of remote server
@remote_dir = '/dev/null'    # Your remote server, use rsync format
@backup_targets = {}         # Hash from local name to remote directory
                             # uses rsync naming format, example:
                             # {
                             #   'www' => 'horseslov@172.16.11.23:/www',
                             #   'logs' => 'horseslov@172.16.11.23:/logs'
                             # }
@build_excludes = [          # Files you do NOT want copied from SOURCE to BUILD
  'Rakefile',                # use rsync format
  'Gemfile',
  'Gemfile.lock',
  '.bundle',
  '.git',
  '.gitignore',
  '.travis.yml',
  'vendor',
  '/tmp'
]

def create_build_dir (build_dir=@build_dir)
  FileUtils.mkdir_p build_dir
  #TODO: output if directory did not exist and we created it
end

namespace :git do
  def source_dir_is_git?
    return false if !File.directory?(@source_dir)
    return system("cd #{@source_dir} && git rev-parse --git-dir > /dev/null 2> /dev/null")
  end

  desc "Incorporate changes from the remote repository into the current branch"
  task :pull do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    puts '⚡️ Pulling git'.blue
    sh "cd '#{@source_dir}'; git pull"
    puts '✅ Pulled'.green
  end

  desc "Displays paths that have differences between the index file and the current HEAD commit"
  task :status do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    puts 'Here are differences between git\'s index file and the current HEAD commit'.blue
    sh "cd #{@source_dir} && git status --short"
  end

  desc "Print the modified date for all files under source control"
  task :stale_report do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    puts '📋 Here is the modification date for each file'.blue
    sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}", noop: true
    puts 'Modified   File'.blue
    sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}", verbose: false
  end

  desc "Save the commit hash to VERSION in the build directory"
  task :save_version do
    if !source_dir_is_git?
      puts "There is no git directory, skipping"
      next
    end
    hash = `cd #{@source_dir} && git rev-parse HEAD`.chomp
    local_changes = `git diff --shortstat`.chomp.length
    File.write(@build_dir + '/VERSION', local_changes > 0 ? "#{hash}*" : "#{hash}")
    puts 'Saved git version to VERSION file'.green
  end
end

namespace :jekyll do
{'fraction_non_alphanumeric': 0.15567682279824163, 'fraction_numerical': 0.012581476428679702, 'mean_word_length': 2.7574031890660593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2721510', 'n_tokens_mistral': 2074, 'n_tokens_neox': 2018, 'n_words': 683}