Skip to content

Commit

Permalink
FEATURE: Handle Youtube RSS feeds (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
xfalcox committed Jul 30, 2021
1 parent d52b361 commit 14eaa14
Show file tree
Hide file tree
Showing 4 changed files with 1,882 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/models/discourse_rss_polling/feed_item.rb
Expand Up @@ -19,6 +19,8 @@ def content
break if content = @accessor.element_content(tag_name)
end

return youtube_embed if is_youtube?

content&.force_encoding('UTF-8')&.scrub
end

Expand All @@ -45,5 +47,15 @@ def categories
def url?(link)
link.present? && link =~ /^https?\:\/\//
end

def is_youtube?
url&.starts_with?('https://www.youtube.com/watch')
end

def youtube_embed
<<~POSTCONTENT
<div><iframe width="#{SiteSetting.max_image_width}" height="#{(SiteSetting.max_image_width / (16.0 / 9)).to_i}" src="https://www.youtube.com/embed/#{@accessor.element_content(:id).split(':').last}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>
POSTCONTENT
end
end
end

0 comments on commit 14eaa14

Please sign in to comment.