Skip to content

Commit 5471682

Browse files
committed
Add title, url, feed_url, summary and athors fields for h-feeds
1 parent c541894 commit 5471682

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

feedparser/lib/feedparser/builder/microformats.rb

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ def build_feed( h )
3434

3535
feed = Feed.new
3636
feed.format = 'html'
37-
38-
### todo: add
39-
## - feed.title
40-
## - feed.url
41-
## - feed.feed_url
42-
## - feed.summary
43-
## - feed.authors
44-
## etc.
37+
feed.title = hy.title
38+
feed.url = hy.url
39+
feed.feed_url = hy.feed_url
40+
feed.summary = hy.summary
41+
feed.authors = hy.authors
4542

4643
hy.entries.each do |entry|
4744
feed.items << build_item( entry )
@@ -55,9 +52,7 @@ def build_author( hy )
5552
author = Author.new
5653

5754
author.name = hy.name
58-
59-
## todo - add:
60-
## author.url
55+
author.url = hy.url
6156

6257
author
6358
end
@@ -91,10 +86,25 @@ def build_item( hy )
9186

9287

9388
class HyFeed
89+
attr_accessor :name
90+
attr_accessor :summary
91+
92+
attr_accessor :url
93+
94+
attr_accessor :authors
9495
attr_accessor :entries
9596

97+
# note: title is an alias for name
98+
alias :title :name
99+
alias :title= :name=
100+
101+
# note: in h-feeds, the feed url is the same as the site url
102+
alias :feed_url :url
103+
alias :feed_url= :url=
104+
96105
def initialize
97-
@entries = []
106+
@entries = []
107+
@authors = []
98108
end
99109
end # class HyFeed
100110

@@ -178,6 +188,28 @@ def build_feed( h )
178188

179189
feed = HyFeed.new
180190

191+
props = h['properties']
192+
193+
if props['name']
194+
feed.name = props['name'].join( ' ')
195+
end
196+
197+
url_str = props.fetch( 'url', [] )[0]
198+
if url_str
199+
entry.url = url_str
200+
end
201+
202+
if props['summary']
203+
entry.summary = props['summary'].join( ' ' )
204+
end
205+
206+
if props['author']
207+
props['author'].each do |author_hash|
208+
pp author_hash
209+
entry.authors << build_author( author_hash )
210+
end
211+
end
212+
181213
h['children'].each_with_index do |item_hash,i|
182214
puts "item #{i+1}:"
183215
pp item_hash
@@ -252,6 +284,7 @@ def build_author( h )
252284

253285
author.name = h['value']
254286

287+
## todo: read author url
255288
## todo/fix: -- note: for now skip possible embedded h-card
256289
author
257290
end # method build_author

0 commit comments

Comments
 (0)