all repos — h3rald @ 152aea630e0d873c643faaaa2768706e04922227

The sources of https://h3rald.com

Created content migration task.
* Closes #1.
h3rald h3rald@h3rald.com
Sat, 08 Aug 2009 16:38:27 +0200
commit

152aea630e0d873c643faaaa2768706e04922227

parent

cc50c9eee3f6eb9771d49973b6bbe0db9ef6a6ec

2 files changed, 44 insertions(+), 0 deletions(-)

jump to
M README.textileREADME.textile

@@ -3,3 +3,7 @@

The following ruby gems are required to compile the site: * nanoc * extlib + +Additionally, the following gems are required to execute db:migration tasks: +* mysql +* sequel
A tasks/db.rake

@@ -0,0 +1,40 @@

+require 'rubygems' +require 'extlib' +require 'pathname' +require 'fileutils' +require 'mysql' +require 'sequel' +require 'yaml' + + +namespace :db do + + task :migrate => [:migrate_contents] do + end + + task :migrate_contents, :db, :usr, :pwd do |t, args| + raise RuntimeError, "Please provide :db, :usr, :pass" unless args[:db] && args[:usr] && args[:pwd] + write_article = lambda do |meta, contents| + path = (meta['type'] == 'article') ? Pathname.new(Dir.pwd)/"content/articles/" : Pathname.new(Dir.pwd)/"content/" + name = "#{meta['permalink']}.#{meta['filter_pre']}" + path.mkpath + (path/name).open('w+') do |f| + f.print "--" + f.puts meta.to_yaml + f.puts "-----" + f.puts contents + end + end + db = Sequel.mysql args[:db], :user => args[:usr], :password => args[:pwd], :host => 'localhost' + db[:contents].where("state = 'published' || type = 'Page'").each do |a| + meta = {} + meta['tags'] = (a[:keywords]) ? a[:keywords].downcase.split(", ") : [] + meta['filter_pre'] = db[:text_filters].where("id = ?", a[:text_filter_id]).get(:name).downcase + meta['permalink'] = a[:permalink] || a[:name] + meta['title'] = a[:title] + meta['type'] = a[:type].downcase + write_article.call meta, a[:body]+a[:extended].to_s + end + end + +end