From 5471682cd91ab302a18c599c8d90d11f5d47e13a Mon Sep 17 00:00:00 2001 From: Daniel Mowitz Date: Tue, 3 Mar 2026 19:25:14 +0100 Subject: [PATCH] Add title, url, feed_url, summary and athors fields for h-feeds --- .../lib/feedparser/builder/microformats.rb | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/feedparser/lib/feedparser/builder/microformats.rb b/feedparser/lib/feedparser/builder/microformats.rb index 3f4956a..7a30a33 100644 --- a/feedparser/lib/feedparser/builder/microformats.rb +++ b/feedparser/lib/feedparser/builder/microformats.rb @@ -34,14 +34,11 @@ def build_feed( h ) feed = Feed.new feed.format = 'html' - - ### todo: add - ## - feed.title - ## - feed.url - ## - feed.feed_url - ## - feed.summary - ## - feed.authors - ## etc. + feed.title = hy.title + feed.url = hy.url + feed.feed_url = hy.feed_url + feed.summary = hy.summary + feed.authors = hy.authors hy.entries.each do |entry| feed.items << build_item( entry ) @@ -55,9 +52,7 @@ def build_author( hy ) author = Author.new author.name = hy.name - - ## todo - add: - ## author.url + author.url = hy.url author end @@ -91,10 +86,25 @@ def build_item( hy ) class HyFeed + attr_accessor :name + attr_accessor :summary + + attr_accessor :url + + attr_accessor :authors attr_accessor :entries + # note: title is an alias for name + alias :title :name + alias :title= :name= + + # note: in h-feeds, the feed url is the same as the site url + alias :feed_url :url + alias :feed_url= :url= + def initialize - @entries = [] + @entries = [] + @authors = [] end end # class HyFeed @@ -178,6 +188,28 @@ def build_feed( h ) feed = HyFeed.new + props = h['properties'] + + if props['name'] + feed.name = props['name'].join( ' ') + end + + url_str = props.fetch( 'url', [] )[0] + if url_str + entry.url = url_str + end + + if props['summary'] + entry.summary = props['summary'].join( ' ' ) + end + + if props['author'] + props['author'].each do |author_hash| + pp author_hash + entry.authors << build_author( author_hash ) + end + end + h['children'].each_with_index do |item_hash,i| puts "item #{i+1}:" pp item_hash @@ -252,6 +284,7 @@ def build_author( h ) author.name = h['value'] + ## todo: read author url ## todo/fix: -- note: for now skip possible embedded h-card author end # method build_author