#!/usr/local/bin/ruby #!ruby # Javascript Workspace Atom Feed # # Copyright (c) 2007 Takashi Yammaiya # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require "cgi" require "time" DATA_DIR = "jsdata" # data directory cgi = CGI.new print "Content-type: text/xml\n\n" #print "Content-Type: application/atom+xml; charset=utf-8\n\n" base = File.dirname(cgi.script_name || 'local') entries = Dir.entries(DATA_DIR).map do |name| matched = name.match(/(.*).txt$/) if (matched) path = DATA_DIR + "/" + name; title = CGI.unescape(matched[1]) summary = "" open(path, "r") do |f| begin summary = CGI.escapeHTML(f.readline).chomp rescue EOFError summary = "" end end mtime = File.mtime(path).iso8601 ctime = File.ctime(path).iso8601 entry = { "path" => path, "title" => title, "mtime" => mtime, "ctime" => ctime, "url" => "http://#{cgi.host}#{base}/workspace.cgi/#{title}", "summary" => summary, } end end entries.reject! { | e | e == nil } entries.sort! { | a, b | b["mtime"] <=> a["mtime"] } mtime = entries.first["mtime"] print < tag:metatoys.org,2007:javascriptworkspace/feed Javascript Workspace Takashi Yamamiya #{mtime} EOT entries.each do | entry | print " \n" print " #{entry["url"]}\n" print " #{entry["title"]}\n" print " \n" print " #{entry["ctime"]}\n" # if (entry["mtime"] != entry["ctime"]) print " #{entry["mtime"]}\n" # end print " #{entry["summary"]}\n" print " \n" end print "\n"