diff --git a/lib/feed_item_accessor.rb b/lib/feed_item_accessor.rb index 4ef70cbf855..93c11c6b377 100644 --- a/lib/feed_item_accessor.rb +++ b/lib/feed_item_accessor.rb @@ -12,6 +12,11 @@ class FeedItemAccessor end def link + if rss_item.respond_to?(:links) + link = rss_item.links&.find { |l| l.rel == "alternate" && l.type == "text/html" } + return link.href if link.respond_to?(:href) + end + try_attribute_or_self(element(:link), :href) end diff --git a/spec/components/feed_item_accessor_spec.rb b/spec/components/feed_item_accessor_spec.rb index c19de62b90a..8a457d8d7ac 100644 --- a/spec/components/feed_item_accessor_spec.rb +++ b/spec/components/feed_item_accessor_spec.rb @@ -32,4 +32,16 @@ describe FeedItemAccessor do it { expect(item_accessor.link).to eq(rss_feed_item.link) } end end + + context 'with multiple links' do + let(:rss_feed) { RSS::Parser.parse(file_from_fixtures('multiple-links.atom', 'feed'), false) } + let(:rss_feed_item) { rss_feed.items.first } + let(:item_accessor) { FeedItemAccessor.new(rss_feed_item) } + + describe '#link' do + it 'gets the web page link' do + expect(item_accessor.link).to eq('http://workspaceupdates.googleblog.com/2022/01/improved-editing-experience-in-google.html') + end + end + end end diff --git a/spec/fixtures/feed/multiple-links.atom b/spec/fixtures/feed/multiple-links.atom new file mode 100644 index 00000000000..d8b0c7d85f6 --- /dev/null +++ b/spec/fixtures/feed/multiple-links.atom @@ -0,0 +1,48 @@ + + + tag:blogger.com,1999:blog-5245696872621940063 + 2022-01-20T08:59:51.049-08:00 + + Google Workspace Updates + This official feed from the Google Workspace team provides essential information about new features and improvements for Google Workspace customers. + + + + ewood + http://www.blogger.com/profile/12341551220176883769 + noreply@blogger.com + + + Blogger + 2675 + 1 + 25 + + + + + tag:blogger.com,1999:blog-5245696872621940063.post-5639928758147944950 + 2022-01-20T08:58:00.001-08:00 + 2022-01-20T08:59:19.910-08:00 + + Improved editing experience in Google Chat on the web + You now can add rich formatting to Chat messages, such as bold, italics, or underlines. + + + + + + + Unknown + noreply@blogger.com + + + + 0 + +