Created
July 26, 2010 01:20
-
-
Save drio/490064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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