onebox 2.2.9 → 2.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +0 -4
- data/lib/onebox/engine.rb +1 -1
- data/lib/onebox/engine/allowlisted_generic_onebox.rb +11 -9
- data/lib/onebox/engine/amazon_onebox.rb +25 -13
- data/lib/onebox/engine/asciinema_onebox.rb +0 -1
- data/lib/onebox/engine/audioboom_onebox.rb +5 -2
- data/lib/onebox/engine/bandcamp_onebox.rb +8 -8
- data/lib/onebox/engine/cloudapp_onebox.rb +12 -12
- data/lib/onebox/engine/coub_onebox.rb +0 -1
- data/lib/onebox/engine/facebook_media_onebox.rb +8 -7
- data/lib/onebox/engine/five_hundred_px_onebox.rb +0 -1
- data/lib/onebox/engine/flickr_onebox.rb +14 -15
- data/lib/onebox/engine/giphy_onebox.rb +0 -1
- data/lib/onebox/engine/github_blob_onebox.rb +4 -0
- data/lib/onebox/engine/github_commit_onebox.rb +12 -15
- data/lib/onebox/engine/github_gist_onebox.rb +1 -2
- data/lib/onebox/engine/github_issue_onebox.rb +16 -18
- data/lib/onebox/engine/github_pullrequest_onebox.rb +9 -1
- data/lib/onebox/engine/gitlab_blob_onebox.rb +4 -0
- data/lib/onebox/engine/google_calendar_onebox.rb +1 -1
- data/lib/onebox/engine/google_docs_onebox.rb +7 -7
- data/lib/onebox/engine/google_drive_onebox.rb +7 -7
- data/lib/onebox/engine/google_maps_onebox.rb +0 -2
- data/lib/onebox/engine/google_photos_onebox.rb +14 -14
- data/lib/onebox/engine/google_play_app_onebox.rb +3 -7
- data/lib/onebox/engine/html.rb +4 -1
- data/lib/onebox/engine/instagram_onebox.rb +2 -2
- data/lib/onebox/engine/kaltura_onebox.rb +8 -6
- data/lib/onebox/engine/opengraph_image.rb +0 -1
- data/lib/onebox/engine/pubmed_onebox.rb +3 -2
- data/lib/onebox/engine/replit_onebox.rb +0 -1
- data/lib/onebox/engine/sketchfab_onebox.rb +8 -8
- data/lib/onebox/engine/slides_onebox.rb +10 -10
- data/lib/onebox/engine/soundcloud_onebox.rb +0 -1
- data/lib/onebox/engine/stack_exchange_onebox.rb +2 -1
- data/lib/onebox/engine/standard_embed.rb +2 -2
- data/lib/onebox/engine/steam_store_onebox.rb +6 -5
- data/lib/onebox/engine/trello_onebox.rb +2 -2
- data/lib/onebox/engine/twitch_clips_onebox.rb +1 -3
- data/lib/onebox/engine/twitch_stream_onebox.rb +1 -2
- data/lib/onebox/engine/twitch_video_onebox.rb +0 -2
- data/lib/onebox/engine/typeform_onebox.rb +7 -6
- data/lib/onebox/engine/vimeo_onebox.rb +9 -7
- data/lib/onebox/engine/wikimedia_onebox.rb +1 -2
- data/lib/onebox/engine/wikipedia_onebox.rb +12 -8
- data/lib/onebox/engine/youku_onebox.rb +7 -7
- data/lib/onebox/engine/youtube_onebox.rb +46 -17
- data/lib/onebox/file_type_finder.rb +0 -1
- data/lib/onebox/helpers.rb +3 -3
- data/lib/onebox/mixins/git_blob_onebox.rb +5 -3
- data/lib/onebox/mixins/github_body.rb +30 -0
- data/lib/onebox/mixins/twitch_onebox.rb +0 -1
- data/lib/onebox/preview.rb +1 -2
- data/lib/onebox/sanitize_config.rb +1 -1
- data/lib/onebox/version.rb +1 -1
- data/templates/github/github_body.mustache +5 -0
- data/templates/githubcommit.mustache +2 -8
- data/templates/githubissue.mustache +7 -9
- data/templates/githubpullrequest.mustache +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b9626bc9bec1d423e617a946df2e4be0334cf6f7693056dc79865b50f127e26
|
4
|
+
data.tar.gz: 9fc7c684bc99a33d356cfbf0c1a085e5dc1531aa6a6a3028670afb05406c4448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a3f999936fbfe289e07b58b424e735d13c2e3132beffb16c41a6094fa42aa0dd1018d544175eba1f1ad7552b26cade7096d72ff286268a097230835d8f9c99d
|
7
|
+
data.tar.gz: 1effdda4c94dc9dbded959fc3acf0a51d6efd09629cccd2e9c2c1df74d637c9b8cb577be7fb79dc90b3ba42125af6dfde0c56e33cb8b31f6d4a72d0090a0fded
|
data/.rspec
CHANGED
data/lib/onebox/engine.rb
CHANGED
@@ -374,15 +374,17 @@ module Onebox
|
|
374
374
|
escaped_image_src = ::Onebox::Helpers.normalize_url_for_output(data[:image])
|
375
375
|
|
376
376
|
<<-HTML
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
377
|
+
<video
|
378
|
+
title='#{data[:title]}'
|
379
|
+
width='#{data[:video_width]}'
|
380
|
+
height='#{data[:video_height]}'
|
381
|
+
style='max-width:100%'
|
382
|
+
poster='#{escaped_image_src}'
|
383
|
+
controls=''
|
384
|
+
>
|
385
|
+
<source src='#{escaped_video_src}'>
|
386
|
+
</video>
|
387
|
+
HTML
|
386
388
|
end
|
387
389
|
|
388
390
|
def embedded_html
|
@@ -14,17 +14,22 @@ module Onebox
|
|
14
14
|
matches_regexp(/^https?:\/\/(?:www\.)?(?:smile\.)?(amazon|amzn)\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br|com\.mx|nl|pl|sa|sg|se|com\.tr|ae)\//)
|
15
15
|
|
16
16
|
def url
|
17
|
-
|
18
|
-
|
17
|
+
@raw ||= nil
|
18
|
+
|
19
|
+
# If possible, fetch the cached HTML body immediately so we can
|
20
|
+
# try to grab the canonical URL from that document,
|
19
21
|
# rather than guess at the best URL structure to use
|
20
|
-
if
|
21
|
-
if
|
22
|
-
@raw ||= Onebox::Helpers.fetch_html_doc(@url, http_params,
|
23
|
-
canonical_link = @raw.at('//link[@rel="canonical"]/@href')
|
24
|
-
return canonical_link.to_s if canonical_link
|
22
|
+
if body_cacher&.respond_to?('cache_response_body?')
|
23
|
+
if body_cacher.cache_response_body?(uri.to_s) && body_cacher.cached_response_body_exists?(uri.to_s)
|
24
|
+
@raw ||= Onebox::Helpers.fetch_html_doc(@url, http_params, body_cacher)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
if @raw
|
29
|
+
canonical_link = @raw.at('//link[@rel="canonical"]/@href')
|
30
|
+
return canonical_link.to_s if canonical_link
|
31
|
+
end
|
32
|
+
|
28
33
|
if match && match[:id]
|
29
34
|
return "https://www.amazon.#{tld}/dp/#{Onebox::Helpers.uri_encode(match[:id])}"
|
30
35
|
end
|
@@ -33,7 +38,7 @@ module Onebox
|
|
33
38
|
end
|
34
39
|
|
35
40
|
def tld
|
36
|
-
@tld
|
41
|
+
@tld ||= @@matcher.match(@url)["tld"]
|
37
42
|
end
|
38
43
|
|
39
44
|
def http_params
|
@@ -45,7 +50,7 @@ module Onebox
|
|
45
50
|
private
|
46
51
|
|
47
52
|
def match
|
48
|
-
@match ||= @url.match(/(?:d|g)p\/(?:product\/|video\/detail\/)?(?<id>[
|
53
|
+
@match ||= @url.match(/(?:d|g)p\/(?:product\/|video\/detail\/)?(?<id>[A-Z0-9]+)(?:\/|\?|$)/mi)
|
49
54
|
end
|
50
55
|
|
51
56
|
def image
|
@@ -60,6 +65,10 @@ module Onebox
|
|
60
65
|
end
|
61
66
|
|
62
67
|
if (landing_image = raw.css("#landingImage")) && landing_image.any?
|
68
|
+
attributes = landing_image.first.attributes
|
69
|
+
|
70
|
+
return attributes["data-old-hires"].to_s if attributes["data-old-hires"]
|
71
|
+
|
63
72
|
landing_image.first["src"].to_s
|
64
73
|
end
|
65
74
|
|
@@ -110,7 +119,7 @@ module Onebox
|
|
110
119
|
end
|
111
120
|
|
112
121
|
result = {
|
113
|
-
link:
|
122
|
+
link: url,
|
114
123
|
title: title,
|
115
124
|
by_info: authors,
|
116
125
|
image: og.image || image,
|
@@ -141,7 +150,7 @@ module Onebox
|
|
141
150
|
end
|
142
151
|
|
143
152
|
result = {
|
144
|
-
link:
|
153
|
+
link: url,
|
145
154
|
title: title,
|
146
155
|
by_info: authors,
|
147
156
|
image: og.image || image,
|
@@ -157,7 +166,7 @@ module Onebox
|
|
157
166
|
else
|
158
167
|
title = og.title || CGI.unescapeHTML(raw.css("title").inner_text)
|
159
168
|
result = {
|
160
|
-
link:
|
169
|
+
link: url,
|
161
170
|
title: title,
|
162
171
|
image: og.image || image,
|
163
172
|
price: price
|
@@ -167,7 +176,10 @@ module Onebox
|
|
167
176
|
result[:by_info] = Onebox::Helpers.clean(result[:by_info].inner_html) if result[:by_info]
|
168
177
|
|
169
178
|
summary = raw.at("#productDescription")
|
170
|
-
|
179
|
+
|
180
|
+
description = og.description || summary&.inner_text
|
181
|
+
description ||= raw.css("meta[name=description]").first&.[]("content")
|
182
|
+
result[:description] = CGI.unescapeHTML(Onebox::Helpers.truncate(description, 250)) if description
|
171
183
|
end
|
172
184
|
|
173
185
|
result[:price] = nil if result[:price].start_with?("$0") || result[:price] == 0
|
@@ -13,14 +13,17 @@ module Onebox
|
|
13
13
|
oembed = get_oembed
|
14
14
|
|
15
15
|
<<-HTML
|
16
|
-
<img
|
16
|
+
<img
|
17
|
+
src="#{oembed.thumbnail_url}"
|
18
|
+
style="max-width: #{oembed.width}px; max-height: #{oembed.height}px;"
|
19
|
+
#{oembed.title_attr}
|
20
|
+
>
|
17
21
|
HTML
|
18
22
|
end
|
19
23
|
|
20
24
|
def to_html
|
21
25
|
get_oembed.html
|
22
26
|
end
|
23
|
-
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -20,16 +20,16 @@ module Onebox
|
|
20
20
|
escaped_src = og.video_secure_url || og.video
|
21
21
|
|
22
22
|
<<-HTML
|
23
|
-
<iframe
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
<iframe
|
24
|
+
src="#{escaped_src}"
|
25
|
+
width="#{og.video_width}"
|
26
|
+
height="#{og.video_height}"
|
27
|
+
scrolling="no"
|
28
|
+
frameborder="0"
|
29
|
+
allowfullscreen
|
30
|
+
></iframe>
|
30
31
|
HTML
|
31
32
|
end
|
32
|
-
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -25,28 +25,28 @@ module Onebox
|
|
25
25
|
|
26
26
|
def link_html(og)
|
27
27
|
<<-HTML
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
<a href='#{og.url}' target='_blank' rel='noopener'>
|
29
|
+
#{og.title}
|
30
|
+
</a>
|
31
|
+
HTML
|
32
32
|
end
|
33
33
|
|
34
34
|
def video_html(og)
|
35
35
|
direct_src = ::Onebox::Helpers.normalize_url_for_output("#{og.get(:url)}/#{og.title}")
|
36
36
|
|
37
37
|
<<-HTML
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
<video width='480' height='360' #{og.title_attr} controls loop>
|
39
|
+
<source src='#{direct_src}' type='video/mp4'>
|
40
|
+
</video>
|
41
|
+
HTML
|
42
42
|
end
|
43
43
|
|
44
44
|
def image_html(og)
|
45
45
|
<<-HTML
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
<a href='#{og.url}' target='_blank' class='onebox' rel='noopener'>
|
47
|
+
<img src='#{og.image}' #{og.title_attr} alt='CloudApp' width='480'>
|
48
|
+
</a>
|
49
|
+
HTML
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -14,13 +14,14 @@ module Onebox
|
|
14
14
|
metadata = get_twitter
|
15
15
|
if metadata.present? && metadata[:card] == "player" && metadata[:player].present?
|
16
16
|
<<-HTML
|
17
|
-
<iframe
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
<iframe
|
18
|
+
src="#{metadata[:player]}"
|
19
|
+
width="#{metadata[:player_width]}"
|
20
|
+
height="#{metadata[:player_height]}"
|
21
|
+
scrolling="no"
|
22
|
+
frameborder="0"
|
23
|
+
allowfullscreen
|
24
|
+
></iframe>
|
24
25
|
HTML
|
25
26
|
else
|
26
27
|
html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html
|
@@ -25,29 +25,28 @@ module Onebox
|
|
25
25
|
album_title = "[Album] #{og.title}"
|
26
26
|
|
27
27
|
<<-HTML
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
</span>
|
28
|
+
<div class='onebox flickr-album'>
|
29
|
+
<a href='#{escaped_url}' target='_blank' rel='noopener'>
|
30
|
+
<span class='outer-box' style='max-width:#{og.image_width}px'>
|
31
|
+
<span class='inner-box'>
|
32
|
+
<span class='album-title'>#{album_title}</span>
|
34
33
|
</span>
|
35
|
-
|
36
|
-
|
37
|
-
</
|
38
|
-
|
34
|
+
</span>
|
35
|
+
<img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
|
36
|
+
</a>
|
37
|
+
</div>
|
38
|
+
HTML
|
39
39
|
end
|
40
40
|
|
41
41
|
def image_html(og)
|
42
42
|
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
43
43
|
|
44
44
|
<<-HTML
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
<a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
|
46
|
+
<img src='#{og.get_secure_image}' #{og.title_attr} alt='Imgur' height='#{og.image_height}' width='#{og.image_width}'>
|
47
|
+
</a>
|
48
|
+
HTML
|
49
49
|
end
|
50
|
-
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -8,17 +8,21 @@ module Onebox
|
|
8
8
|
def self.git_regexp
|
9
9
|
/^https?:\/\/(www\.)?github\.com.*\/blob\//
|
10
10
|
end
|
11
|
+
|
11
12
|
def self.onebox_name
|
12
13
|
"githubblob"
|
13
14
|
end
|
14
15
|
|
15
16
|
include Onebox::Mixins::GitBlobOnebox
|
17
|
+
|
16
18
|
def raw_regexp
|
17
19
|
/github\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
|
18
20
|
end
|
21
|
+
|
19
22
|
def raw_template(m)
|
20
23
|
"https://raw.githubusercontent.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
|
21
24
|
end
|
25
|
+
|
22
26
|
def title
|
23
27
|
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/github\.com\//, ''))
|
24
28
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../mixins/github_body'
|
4
|
+
|
3
5
|
module Onebox
|
4
6
|
module Engine
|
5
7
|
class GithubCommitOnebox
|
6
8
|
include Engine
|
7
9
|
include LayoutSupport
|
8
10
|
include JSON
|
11
|
+
include Onebox::Mixins::GithubBody
|
9
12
|
|
10
13
|
matches_regexp Regexp.new("^https?://(?:www\.)?(?:(?:\w)+\.)?(github)\.com(?:/)?(?:.)*/commit/")
|
11
14
|
always_https
|
@@ -17,36 +20,30 @@ module Onebox
|
|
17
20
|
private
|
18
21
|
|
19
22
|
def match
|
20
|
-
return @match if @match
|
23
|
+
return @match if defined?(@match)
|
21
24
|
|
22
25
|
@match = @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/commit/(?<sha>[^/]+)})
|
23
|
-
|
24
|
-
@match = @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<pr>[^/]+)/commit/(?<sha>[^/]+)}) if @match.nil?
|
26
|
+
@match ||= @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<pr>[^/]+)/commit/(?<sha>[^/]+)})
|
25
27
|
|
26
28
|
@match
|
27
29
|
end
|
28
30
|
|
29
31
|
def data
|
30
32
|
result = raw.clone
|
31
|
-
result['link'] = link
|
32
|
-
result['title'] = result['commit']['message'].split("\n").first
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
lines = result['commit']['message'].split("\n")
|
35
|
+
result['title'] = lines.first
|
36
|
+
result['body'], result['excerpt'] = compute_body(lines[1..lines.length].join("\n"))
|
36
37
|
|
37
|
-
message_words = message.gsub("\n\n", "\n").gsub("\n", "<br>").split(" ")
|
38
|
-
max_words = 20
|
39
|
-
result['message'] = message_words[0..max_words].join(" ")
|
40
|
-
result['message'] += "..." if message_words.length > max_words
|
41
|
-
result['message'] = result['message'].gsub("<br>", "\n")
|
42
|
-
end
|
43
|
-
|
44
|
-
ulink = URI(link)
|
45
38
|
committed_at = Time.parse(result['commit']['author']['date'])
|
46
39
|
result['committed_at'] = committed_at.strftime("%I:%M%p - %d %b %y %Z")
|
47
40
|
result['committed_at_date'] = committed_at.strftime("%F")
|
48
41
|
result['committed_at_time'] = committed_at.strftime("%T")
|
42
|
+
|
43
|
+
result['link'] = link
|
44
|
+
ulink = URI(link)
|
49
45
|
result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
|
46
|
+
|
50
47
|
result
|
51
48
|
end
|
52
49
|
end
|
@@ -9,7 +9,7 @@ module Onebox
|
|
9
9
|
|
10
10
|
MAX_FILES = 3
|
11
11
|
|
12
|
-
matches_regexp
|
12
|
+
matches_regexp(/^http(?:s)?:\/\/gist\.(?:(?:\w)+\.)?(github)\.com(?:\/)?/)
|
13
13
|
always_https
|
14
14
|
|
15
15
|
def url
|
@@ -76,7 +76,6 @@ module Onebox
|
|
76
76
|
@lines ||= @json["content"].split("\n")
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
80
79
|
end
|
81
80
|
end
|
82
81
|
end
|