mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-04-29 17:19:55 +08:00
Some checks are pending
Licenses / run (push) Waiting to run
Linting / run (push) Waiting to run
Publish Assets / publish-assets (push) Waiting to run
Tests / core backend (push) Waiting to run
Tests / plugins backend (push) Waiting to run
Tests / core frontend (Chrome) (push) Waiting to run
Tests / plugins frontend (push) Waiting to run
Tests / themes frontend (push) Waiting to run
Tests / core system (push) Waiting to run
Tests / plugins system (push) Waiting to run
Tests / themes system (push) Waiting to run
Tests / core frontend (Firefox ESR) (push) Waiting to run
Tests / core frontend (Firefox Evergreen) (push) Waiting to run
Tests / chat system (push) Waiting to run
Tests / merge (push) Blocked by required conditions
Lazily loaded videos currently won't be picked up by search engines as they do not contain an iframe or VideoObject. This commit uses a new API `build_plugin_html "server:topic-show-crawler-post-end"` to insert populated [ld+json](https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data#supported-formats) into the end of each post which has a video. Results: - https://search.google.com/test/rich-results/result?id=vegb8Qkz7HThsMbFaeN2AQ - https://search.google.com/test/rich-results/result?id=asumX41RneM2tMstchv45A - (vimeo) https://search.google.com/test/rich-results/result?id=EZWOMJCkDqEQIHfOLkSkcw Note: There were originally two ways around this - add each VideoObject to the `post.cook` all the time agnostic of crawler view - or add them to the `<head>` with appropriate metadata, needing to duplicate all post meta data within a `isPartOf` attribute. I chose to create a new api so that we can satisfy both "only add the meta data in crawler view" and prevent post metadata duplication.
31 lines
873 B
Ruby
31 lines
873 B
Ruby
# 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
|