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:
Jan Cernik
2023-03-29 12:54:25 -03:00
committed by GitHub
parent 86f5abfa18
commit afe3e36363
41 changed files with 672 additions and 510 deletions

View File

@ -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