summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorLars Henrik Mai <lars.mai@kontinui.de>2014-04-08 15:49:24 +0200
committerLars Henrik Mai <lars.mai@kontinui.de>2014-04-08 15:49:24 +0200
commit6db87280862479117821a25cbf85a77f464bb259 (patch)
tree4418f1026cb8b94586e610bc8db8654b178c8bf4 /script
parent9cbb3e63db68bfc7d38a8b1368d61dd9456af446 (diff)
added script to convert old news items to markdown
Diffstat (limited to 'script')
-rwxr-xr-xscript/converter.rb54
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