2012-01-18 37 views
2

我正在使用Feedzirra更新RSS提要。我目前正在獲取像這樣的單個條目的縮略圖。用Feedzirra餵食縮略圖

Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",:value => :url, :as => :thumbnail) 
feed = Feedzirra::Feed.fetch_and_parse("http://somefeed") 
entry = feed.entries.first.thumbnail 

那偉大工程,但我也希望得到該網站的每個條目是從哪裏來的縮略圖(在瀏覽器中顯示的圖標的網址,通常是公司的標誌旁)。做這個的最好方式是什麼?

回答

0

我通常使用favicon.ico(16x16)作爲供稿網址的主機名稱。你可以將它伸展到24x24而不會看起來太糟糕。

def get_fav_icon_url 
    "http://" + get_host + "/favicon.ico" 
end 

def get_host 
    url = self.url 
    url = "http://#{url}" unless url.start_with?('http') 
    uri = URI.parse(url) 
    uri.host.downcase 
end