From 6db87280862479117821a25cbf85a77f464bb259 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Tue, 8 Apr 2014 15:49:24 +0200 Subject: added script to convert old news items to markdown --- script/converter.rb | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 script/converter.rb 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 -- cgit v1.2.1