Skip to content

Commit f9d6731

Browse files
committed
feat(auto_source): replace stylesheet workaround
Replaced the previous RSS construction with a new feed builder to simplify code and improve maintainability. Updated caching logic to align with the new structure, enhancing response handling for auto-source features.
1 parent fb5f461 commit f9d6731

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

routes/auto_source.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,16 @@ class App
2727

2828
response['Content-Type'] = CONTENT_TYPE_RSS
2929

30-
url = Addressable::URI.parse(Base64.urlsafe_decode64(encoded_url)).to_s
31-
rss = Html2rss.auto_source(url, strategy:)
30+
url = Addressable::URI.parse(Base64.urlsafe_decode64(encoded_url))
3231

33-
# Unfortunately, Ruby's rss gem does not provide a direct method to
34-
# add an XML stylesheet to the RSS::RSS object itself.
35-
stylesheet = Html2rss::RssBuilder::Stylesheet.new(href: '/rss.xsl', type: 'text/xsl').to_xml
32+
feed = Html2rss.feed(stylesheets: [{ href: '/rss.xsl', type: 'text/xsl' }],
33+
strategy:,
34+
channel: { url: url.to_s },
35+
auto_source: {})
3636

37-
xml_content = rss.to_xml
38-
xml_content.sub!(/^<\?xml version="1.0" encoding="UTF-8"\?>/,
39-
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n#{stylesheet}")
37+
HttpCache.expires(response, AutoSource.ttl_in_seconds(feed), cache_control: 'private, must-revalidate')
4038

41-
HttpCache.expires response,
42-
AutoSource.ttl_in_seconds(rss),
43-
cache_control: 'private, must-revalidate'
44-
45-
xml_content
39+
feed.to_xml
4640
end
4741
else
4842
# auto_source feature is disabled

0 commit comments

Comments
 (0)