<commit_before>require 'yaml'
require 'liquid'
require 'redcarpet'
require 'time'
require 'rouge'
require 'rouge/plugins/redcarpet'

class Post
  attr_accessor :content
  attr_accessor :vars

  DEFAULT_VARS = {
    'layout' => 'default',
    'markup' => 'ext',
    'timestamp' => DateTime.now
  }

  def initialize(content)
    @content = strip_yaml(content)
    @vars = DEFAULT_VARS.merge(YAML::load(content))
  end

  def permalink
    if @vars.has_key?('permalink')
      "#{ path }/#{ normalize_custom_permalink }.html"
    else
      "#{ path }/#{ slug }.html"
    end
  end

  def slug
    @slug ||= @vars['title'].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
  end

  def path
    @path ||= "/#{ date.year }/#{ date.month.to_s.rjust(2, '0') }/#{ date.day.to_s.rjust(2, '0') }"
  end

  def html
    @html ||= Liquid::Template.parse(markdown_to_html).render(@vars)
  end

  def timestamp
    @timestamp ||= @vars['timestamp']
  end

  def title
    @title ||= @vars['title']
  end

  def tags
    return unless @vars['tags']
    @tags ||= @vars['tags'].split(',').map { |x| x.strip }.sort
  end

  def external_link
    @external_link ||= @vars['external_link']
  end

  def title_link
    @title_link ||= if has_external_link?
        external_link
      else
        permalink
      end
  end

  def post_type
    @post_type ||= has_external_link? ? :link_post : :self_post
  end

  def to_liquid
    {
      'html' => html,
      'title' => title,
      'permalink' => permalink,
      'slug' => slug,
      'timestamp' => timestamp,
      'tags' => tags,
      'external_link' => external_link,
      'post_type' => post_type.to_s,
      'title_link' => title_link
    }
  end

  protected
  def normalize_custom_permalink
    permalink = @vars['permalink']
    if permalink[0] == '/'
      return permalink[1..-1]<commit_msg>output timestamp in template as iso8601 format<commit_after>require 'yaml'
require 'liquid'
require 'redcarpet'
require 'time'
require 'rouge'
require 'rouge/plugins/redcarpet'

class Post
  attr_accessor :content
  attr_accessor :vars

  DEFAULT_VARS = {
    'layout' => 'default',
    'markup' => 'ext',
    'timestamp' => DateTime.now
  }

  def initialize(content)
    @content = strip_yaml(content)
    @vars = DEFAULT_VARS.merge(YAML::load(content))
  end

  def permalink
    if @vars.has_key?('permalink')
      "#{ path }/#{ normalize_custom_permalink }.html"
    else
      "#{ path }/#{ slug }.html"
    end
  end

  def slug
    @slug ||= @vars['title'].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
  end

  def path
    @path ||= "/#{ date.year }/#{ date.month.to_s.rjust(2, '0') }/#{ date.day.to_s.rjust(2, '0') }"
  end

  def html
    @html ||= Liquid::Template.parse(markdown_to_html).render(@vars)
  end

  def timestamp
    @timestamp ||= @vars['timestamp']
  end

  def title
    @title ||= @vars['title']
  end

  def tags
    return unless @vars['tags']
    @tags ||= @vars['tags'].split(',').map { |x| x.strip }.sort
  end

  def external_link
    @external_link ||= @vars['external_link']
  end

  def title_link
    @title_link ||= if has_external_link?
        external_link
      else
        permalink
      end
  end

  def post_type
    @post_type ||= has_external_link? ? :link_post : :self_post
  end

  def to_liquid
    {
      'html' => html,
      'title' => title,
      'permalink' => permalink,
      'slug' => slug,
      'timestamp' => timestamp.iso8601,
      'tags' => tags,
      'external_link' => external_link,
      'post_type' => post_type.to_s,
      'title_link' => title_link
    }
  end

  protected
  def normalize_custom_permalink
    permalink = @vars['permalink']
    if permalink[0] == '/'
      return permalink[1..-1]
{'fraction_non_alphanumeric': 0.15990325181402848, 'fraction_numerical': 0.005912389142703574, 'mean_word_length': 2.8213552361396306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6156279', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1355, 'n_words': 281}