The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Fixing relative URLs in the reading list

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Green

Posts: 102
Nickname: darwinian
Registered: Dec, 2005

Adam Green is the author of Ruby.Darwinianweb.com
Fixing relative URLs in the reading list Posted: Feb 13, 2006 9:00 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Adam Green.
Original Post: Fixing relative URLs in the reading list
Feed Title: ruby.darwinianweb.com
Feed URL: http://www.nemesis-one.com/rss.xml
Feed Description: Adam Green's Ruby development site
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Adam Green
Latest Posts From ruby.darwinianweb.com

Advertisement
I've discovered that lots of blogs are using relative addresses within the <link> tags that I use for autodiscovery of feeds. For example, they are using a URL of "/rss.xml," instead of "http://myblog.com/rss.xml". This is a no no, and since XML people are a rather anal group, they refuse to convert these to absolute addreses when they write aggregators. Instead feeds with relative addresses are just ignored. So I've modified by OPML creation script to convert relative addresses to absolute. The changed section of code is below.

tmopml.rb

       # Find the first feed link.
if tag.match(('rel=\"alternate\"') &&
('application\/rss\+xml'||'application\/rdf\+xml'||'text\/xml'||'application\/atom\+xml'||'application\/x.atom\+xml'||'application\/x-atom\+xml') ) &&
(not feedfound)



# Extract the feed's URL
matchdata = /href=\".*?\"/.match(tag)
matchstr = matchdata.to_s
xmlurl = matchstr[6..matchstr.length-2]
feedfound = true



# NEW CODE
# Fix relative feed addresses.
require "uri"
xmluri = URI.parse(xmlurl)
if xmluri.relative?
htmluri = URI.parse(htmlurl)
xmlurl = htmluri.merge(xmlurl)
xmlurl = xmlurl.to_s
end
# NEW CODE



opmlfile.puts(' <outline type="rss" text="' + title + '" xmlUrl="' + xmlurl + '" htmlUrl="' + htmlurl + '" />')



end

Read: Fixing relative URLs in the reading list

Topic: Rails Recipes in Beta Previous Topic   Next Topic Topic: What&#8217;s the most productive language/framework/tool you&#8217;ve ever worked with?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use