#!/usr/local/bin/ruby -Ke case ENV['QUERY_STRING'] when /^([0-9]{4})([0-9]{2})$/ if FileTest::exist?("diary/html/#{$1}/#{$2}.html") print "Content-type: text/html\n\n" print File::open("diary/html/#{$1}/#{$2}.html").read else print "Content-type: text/plain\n\n" print "その月の日記はありません\n" end when /^([0-9]{4})([0-9]{2})([0-9]{2})$/ year = $1; month=$2; day=$3 if FileTest::exist?("diary/html/#{year}/#{month+day}.html") print "Content-type: text/html\n\n" article = File::open("diary/html/#{year}/#{month+day}.html").read File::open("diary/template/month.html").each_line{|line| if /^\s*\s*$/ =~ line print article elsif /^\s*