mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Don’t display error if only error is a missing image (#12216)
`Onebox.preview` can return 0-to-n errors, where the errors are missing OpenGraph attributes (e.g. title, description, image, etc.). If any of these attributes are missing, we construct an error message and attach it to the Oneboxer preview HTML. The error message is something like: “Sorry, we were unable to generate a preview for this web page, because the following oEmbed / OpenGraph tags could not be found: description, image” However, if the only missing tag is `image` we don’t need to display the error, as we have enough other data (title, description, etc.) to construct a useful/complete Onebox.
This commit is contained in:
@ -402,21 +402,25 @@ module Oneboxer
|
||||
|
||||
# NOTE: Call r.errors after calling placeholder_html
|
||||
if r.errors.any?
|
||||
missing_attributes = r.errors.keys.map(&:to_s).sort.join(I18n.t("word_connector.comma"))
|
||||
error_message = I18n.t("errors.onebox.missing_data", missing_attributes: missing_attributes, count: r.errors.keys.size)
|
||||
args = r.data.merge(error_message: error_message)
|
||||
error_keys = r.errors.keys
|
||||
skip_if_only_error = [:image]
|
||||
unless error_keys.length == 1 && skip_if_only_error.include?(error_keys.first)
|
||||
missing_attributes = error_keys.map(&:to_s).sort.join(I18n.t("word_connector.comma"))
|
||||
error_message = I18n.t("errors.onebox.missing_data", missing_attributes: missing_attributes, count: error_keys.size)
|
||||
args = r.data.merge(error_message: error_message)
|
||||
|
||||
if result[:preview].blank?
|
||||
result[:preview] = preview_error_onebox(args)
|
||||
else
|
||||
doc = Nokogiri::HTML5::fragment(result[:preview])
|
||||
aside = doc.at('aside')
|
||||
if result[:preview].blank?
|
||||
result[:preview] = preview_error_onebox(args)
|
||||
else
|
||||
doc = Nokogiri::HTML5::fragment(result[:preview])
|
||||
aside = doc.at('aside')
|
||||
|
||||
if aside
|
||||
# Add an error message to the preview that was returned
|
||||
error_fragment = preview_error_onebox_fragment(args)
|
||||
aside.add_child(error_fragment)
|
||||
result[:preview] = doc.to_html
|
||||
if aside
|
||||
# Add an error message to the preview that was returned
|
||||
error_fragment = preview_error_onebox_fragment(args)
|
||||
aside.add_child(error_fragment)
|
||||
result[:preview] = doc.to_html
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user