[Vit-discuss] content refreshness or lack of [was Brainstorming]
Hugh Sasse Staff Elec Eng
hgs at dmu.ac.uk
Thu Feb 24 07:32:35 EST 2005
On Wed, 23 Feb 2005, James Britt wrote:
> I recall having assorted problems getting rubyxml.com to correctly
> show up on the list whenever I added new content. After a while I
> just forgot about it.
There are problems: Apache doesn't seem to produce a Last-Modified
Header
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29
and I can't figure out how to enable it. There are things to do so
with mod_perl, and for active pages, but there seems tobe nothing in
the core to do it. As a result things don't get sorted correctly.
However, the stuff below may be of some use to someone. Yes, it
could be improved, but it does enough for me now.
Hugh
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>List of active Ruby Sites</title>
</head>
<body>
<h1>List of active Ruby Sites</h1>
<%
require 'net/http'
require 'uri'
require 'date'
# Get a list of sites to process
class Site
attr_accessor :url, :name, :date, :failed
def initialize(url, name)
@url = url; @name = name;
@date = DateTime.now;
@failed = false
end
end
Sites = [Site.new('http://www.ruby-lang.org/', 'www.ruby-lang.org/'),
Site.new('http://redhanded.hobix.com/', 'Redhanded'),
Site.new('http://www.ruby-doc.org/', 'Ruby-doc'),
Site.new('http://www.rubyquiz.com/', 'Ruby Quiz'),
Site.new('http://rubyforge.org/', 'RubyForge'),
Site.new('http://rubyxml.com/', 'Ruby XML'),
Site.new('http://raa.ruby-lang.org/', 'Ruby
Application Archive'),
Site.new('http://www.rubygarden.org/', 'RubyGarden')]
Sites.each {|site|
uri = URI.parse(site.url)
host = uri.host
port = uri.port
path = uri.path
begin
Net::HTTP.start(host, port) {|http|
response = http.request_head(path)
if response.key?('last-modified')
site.date = DateTime.parse(response['last-modified'])
else
site.date = DateTime.civil(1970)
end
}
rescue
site.failed = true
end
}
%>
<p>Note, Dates of 1970 mean the server doesn't provide a
Last-Modified: header.</p>
<ul><% Sites.sort_by{|x| x.date}.reverse.each{|site|
unless site.failed
%>
<li><a href="<%= site.url %>"><%= site.name %> ...
[<%= site.date.to_s %>]</a></li>
<% else %>
<li> Could not access <a href="<%= site.url %>"><%=
site.name %> </li>
<% end %>
<% } %></ul>
<p>Page generated <%= DateTime.now %> with erb </p>
</body>
</html>
More information about the vit-discuss
mailing list