mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 21:21:19 +08:00
DEV: Remove lazy-yt and replace with lazy-videos (#20722)
- Refactors the old plugin to remove jquery usage - Adds support for Vimeo videos (default on) and Tiktok (experimental and default off)
This commit is contained in:
31
plugins/discourse-lazy-videos/lib/lazy-videos/lazy_tiktok.rb
Normal file
31
plugins/discourse-lazy-videos/lib/lazy-videos/lazy_tiktok.rb
Normal file
@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "onebox"
|
||||
|
||||
class Onebox::Engine::TiktokOnebox
|
||||
include Onebox::Engine
|
||||
alias_method :default_onebox_to_html, :to_html
|
||||
|
||||
def to_html
|
||||
if SiteSetting.lazy_videos_enabled && SiteSetting.lazy_tiktok_enabled &&
|
||||
oembed_data.embed_product_id
|
||||
thumbnail_url = oembed_data.thumbnail_url
|
||||
escaped_title = ERB::Util.html_escape(oembed_data.title)
|
||||
|
||||
<<~HTML
|
||||
<div class="tiktok-onebox lazy-video-container"
|
||||
data-video-id="#{oembed_data.embed_product_id}"
|
||||
data-video-title="#{escaped_title}"
|
||||
data-provider-name="tiktok">
|
||||
<a href="#{url}" target="_blank">
|
||||
<img class="tiktok-thumbnail"
|
||||
src="#{thumbnail_url}"
|
||||
title="#{escaped_title}">
|
||||
</a>
|
||||
</div>
|
||||
HTML
|
||||
else
|
||||
default_onebox_to_html
|
||||
end
|
||||
end
|
||||
end
|
31
plugins/discourse-lazy-videos/lib/lazy-videos/lazy_vimeo.rb
Normal file
31
plugins/discourse-lazy-videos/lib/lazy-videos/lazy_vimeo.rb
Normal file
@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "onebox"
|
||||
|
||||
class Onebox::Engine::VimeoOnebox
|
||||
include Onebox::Engine
|
||||
alias_method :default_onebox_to_html, :to_html
|
||||
|
||||
def to_html
|
||||
if SiteSetting.lazy_videos_enabled && SiteSetting.lazy_vimeo_enabled
|
||||
video_id = oembed_data[:video_id]
|
||||
thumbnail_url = "https://vumbnail.com/#{oembed_data[:video_id]}.jpg"
|
||||
escaped_title = ERB::Util.html_escape(og_data.title)
|
||||
|
||||
<<~HTML
|
||||
<div class="vimeo-onebox lazy-video-container"
|
||||
data-video-id="#{video_id}"
|
||||
data-video-title="#{escaped_title}"
|
||||
data-provider-name="vimeo">
|
||||
<a href="https://vimeo.com/#{video_id}" target="_blank">
|
||||
<img class="vimeo-thumbnail"
|
||||
src="#{thumbnail_url}"
|
||||
title="#{escaped_title}">
|
||||
</a>
|
||||
</div>
|
||||
HTML
|
||||
else
|
||||
default_onebox_to_html
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "onebox"
|
||||
|
||||
class Onebox::Engine::YoutubeOnebox
|
||||
include Onebox::Engine
|
||||
alias_method :default_onebox_to_html, :to_html
|
||||
|
||||
def to_html
|
||||
if SiteSetting.lazy_videos_enabled && SiteSetting.lazy_youtube_enabled && video_id &&
|
||||
!params["list"]
|
||||
result = parse_embed_response
|
||||
result ||= get_opengraph.data
|
||||
|
||||
thumbnail_url = "https://img.youtube.com/vi/#{video_id}/maxresdefault.jpg"
|
||||
|
||||
begin
|
||||
Onebox::Helpers.fetch_response(thumbnail_url)
|
||||
rescue StandardError
|
||||
thumbnail_url = result[:image]
|
||||
end
|
||||
|
||||
escaped_title = ERB::Util.html_escape(video_title)
|
||||
|
||||
<<~HTML
|
||||
<div class="youtube-onebox lazy-video-container"
|
||||
data-video-id="#{video_id}"
|
||||
data-video-title="#{escaped_title}"
|
||||
data-provider-name="youtube">
|
||||
<a href="https://www.youtube.com/watch?v=#{video_id}" target="_blank">
|
||||
<img class="youtube-thumbnail"
|
||||
src="#{thumbnail_url}"
|
||||
title="#{escaped_title}">
|
||||
</a>
|
||||
</div>
|
||||
HTML
|
||||
else
|
||||
default_onebox_to_html
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user