#!/usr/bin/env ruby
#
# Fix line endings on content pages and add blank line at the end
#

$LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '../lib'))

require 'configuration'

# use production configuration
CONF = Configuration.load(:production)

# page path should be at data/pages
PAGE_PATH = File.join(CONF.data_dir, 'pages')

# replace CRLF with LF, add newline at end if needed
Dir[File.join(PAGE_PATH, "*.textile")].each do |file|
  s = open(file, 'r').read
  s.gsub!(/\r\n/, "\n")
  s += "\n" unless s[-1..-1] == "\n"
  open(file, 'w') {|f| f << s }
end
