mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-18 15:48:22 +00:00
parent
cbdd8edf68
commit
8a5b57f668
|
@ -101,9 +101,7 @@ class LinkDetailsExtractor
|
||||||
end
|
end
|
||||||
|
|
||||||
def json
|
def json
|
||||||
@json ||= root_array(Oj.load(@data))
|
@json ||= root_array(Oj.load(@data)).compact.find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {}
|
||||||
.map { |node| JSON::LD::API.compact(node, 'https://schema.org') }
|
|
||||||
.find { |node| SUPPORTED_TYPES.include?(node['type']) } || {}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -79,16 +79,6 @@ RSpec.describe LinkDetailsExtractor do
|
||||||
},
|
},
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
let(:html) { <<~HTML }
|
|
||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<script type="application/ld+json">
|
|
||||||
#{ld_json}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
HTML
|
|
||||||
|
|
||||||
shared_examples 'structured data' do
|
shared_examples 'structured data' do
|
||||||
it 'extracts the expected values from structured data' do
|
it 'extracts the expected values from structured data' do
|
||||||
|
@ -234,27 +224,21 @@ RSpec.describe LinkDetailsExtractor do
|
||||||
},
|
},
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
let(:html) { <<~HTML }
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="application/ld+json">
|
||||||
|
#{ld_json}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
|
||||||
it 'joins author names' do
|
it 'joins author names' do
|
||||||
expect(subject.author_name).to eq 'Author 1, Author 2'
|
expect(subject.author_name).to eq 'Author 1, Author 2'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with named graph' do
|
|
||||||
let(:ld_json) do
|
|
||||||
{
|
|
||||||
'@context' => 'https://schema.org',
|
|
||||||
'@graph' => [
|
|
||||||
'@type' => 'NewsArticle',
|
|
||||||
'headline' => "What's in a name",
|
|
||||||
],
|
|
||||||
}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'descends into @graph node' do
|
|
||||||
expect(subject.title).to eq "What's in a name"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when Open Graph protocol data is present' do
|
context 'when Open Graph protocol data is present' do
|
||||||
|
|
Loading…
Reference in a new issue