Sunday December 28, 2008
This site have been through its share of blogging systems over the years, wordpress, textpattern and mephisto in recent times. I finally grew tired of trying to bring my now ancient Mephisto install back to life whenever I wanted to write something (thankfully it writes completely cached pages on the frontend).
I decided to go with something a little more low-fi, and thus comfortable this time around. Webby is a nice little website generator framework that generates markup from static text files. No databases and myriad of frameworks to deal with, just plain old textfiles in a git repository with a post-commit hook. Another upside is the fact that I can “update” the site during offline periods, like a holiday season like this.
The only problem with static sites is the fact that they are static; no comments. So I’m trying out Disqus, even though I hate being dependent on other services like this.
Here’s the script I used to write out all the existing entries from Mephisto:
require "rubygems"
require "activerecord"
ActiveRecord::Base.establish_connection({
:adapter => "mysql",
:database => "theexciter_mephisto_prod",
:username => "user",
:password => "pass",
:host => "localhost",
})
class Content < ActiveRecord::Base; end
class Article < Content
has_many :comments
end
class Comment < Content
belongs_to :article
end
Content.find(:all, :conditions => "type = 'Article'").each do |article|
outfile = File.join(File.dirname(__FILE__), "content/articles", "#{article.permalink}.txt")
header = <<-eoh
#{'-'*3}
layout: post
title: #{article.title}
created_at: #{article.published_at.to_yaml.sub(/^-\-\-\s/, "").chomp}
filter:
- erb
- textile
#{'-'*3}
eoh
File.open(outfile, "w") do |f|
f.puts header
f.puts
f.puts article.body
f.puts
article.comments.each do |comment|
# comment markup omitted for brevity
end
end
end
Changing blog software is the ultimate exercise in yak-shaving, since what you really should be doing is writing posts instead…