diff options
Diffstat (limited to 'script')
-rwxr-xr-x | script/converter.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/script/converter.rb b/script/converter.rb new file mode 100755 index 0000000..ec57404 --- /dev/null +++ b/script/converter.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby + +require 'reverse_markdown' + +class OldNewsItem + + RE_TITLE = /\#{3}(.*)/ + RE_DATE = /(\d+-\d+-\d+).*/ + + attr_reader :html, :markdown + + def initialize(filename) + @filename = filename + @html = File.read(@filename) + end + + def self.convert(filename) + new(filename).converted + end + + def date + @filename[RE_DATE,1] + end + + def markdown + @markdown ||= ReverseMarkdown.convert(@html) + end + + def title + markdown[RE_TITLE,1].lstrip + end + + def body + markdown.gsub(RE_TITLE,'').lstrip + end + + def frontmatter + <<-EOS +--- +title: "#{title}" +date: #{date} +--- + EOS + end + + def converted + frontmatter << body + end + +end + +if __FILE__ == $0 + puts OldNewsItem.convert(ARGV.shift) +end |