mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:55:25 +08:00
FIX: Use first supported type item when JSON-LD returns array (#17217)
This commit is contained in:
@ -4,6 +4,7 @@ module Onebox
|
||||
class JsonLd < Normalizer
|
||||
# Full schema.org hierarchy can be found here: https://schema.org/docs/full.html
|
||||
MOVIE_JSON_LD_TYPE = "Movie"
|
||||
SUPPORTED_TYPES = [MOVIE_JSON_LD_TYPE]
|
||||
|
||||
def initialize(doc)
|
||||
@data = extract(doc)
|
||||
@ -17,6 +18,11 @@ module Onebox
|
||||
doc.css('script[type="application/ld+json"]').each do |element|
|
||||
parsed_json = parse_json(element.text)
|
||||
|
||||
if parsed_json.kind_of?(Array)
|
||||
parsed_json = parsed_json.detect { |x| SUPPORTED_TYPES.include?(x["@type"]) }
|
||||
return {} if !parsed_json
|
||||
end
|
||||
|
||||
case parsed_json["@type"]
|
||||
when MOVIE_JSON_LD_TYPE
|
||||
return Onebox::Movie.new(parsed_json).to_h
|
||||
|
Reference in New Issue
Block a user