Skip to content

Instantly share code, notes, and snippets.

@drio
Created July 26, 2010 01:20
Show Gist options
  • Save drio/490064 to your computer and use it in GitHub Desktop.
Save drio/490064 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
=begin
Pass a dir (output ?)
Find all the txt
Per each txt (tcpWindowSize.txt)
Create output/2007-07-25.title.html
---
layout: post
title: tz
--
>> content
=end
require 'find'
require 'fileutils'
i_dir = ARGV[0]
o_dir = "./output"
header = <<END
---
layout: POST
title: TITLE
--
END
FileUtils.mkdir_p o_dir
Find.find(i_dir) do |p|
if p =~ /txt$/
title = p.split("/")[-1].match(/(.+)\.txt$/)[1]
m_time = File::Stat.new(p).mtime.strftime("%Y-%m-%d")
content = header + File.open(p).read
n_file = "./output/" + m_time + "." + title + ".html"
File.open(n_file, "w") {|f| f.puts content}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment