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
@@ -1,5 +1,7 @@
|
|
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 GithubIssueOnebox
|
@@ -7,7 +9,9 @@ module Onebox
|
|
7
9
|
include Engine
|
8
10
|
include LayoutSupport
|
9
11
|
include JSON
|
10
|
-
|
12
|
+
include Onebox::Mixins::GithubBody
|
13
|
+
|
14
|
+
matches_regexp(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?github\.com\/(?<org>.+)\/(?<repo>.+)\/issues\/([[:digit:]]+)/)
|
11
15
|
always_https
|
12
16
|
|
13
17
|
def url
|
@@ -22,32 +26,26 @@ module Onebox
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def data
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
content_words = body_text.gsub("\n\n", "\n").gsub("\n", "<br>").split(" ") #one pass of removing double newline, then we change \n to <br> and later on we revert it back to \n this is a workaround to avoid losing newlines after we join it back.
|
29
|
-
max_words = 20
|
30
|
-
short_content = content_words[0..max_words].join(" ")
|
31
|
-
short_content += "..." if content_words.length > max_words
|
32
|
-
|
33
|
-
created_at = Time.parse(@raw['created_at'])
|
34
|
-
closed_at = Time.parse(@raw['closed_at']) if @raw['closed_at']
|
35
|
-
|
29
|
+
created_at = Time.parse(raw['created_at'])
|
30
|
+
closed_at = Time.parse(raw['closed_at']) if raw['closed_at']
|
31
|
+
body, excerpt = compute_body(raw['body'])
|
36
32
|
ulink = URI(link)
|
33
|
+
|
37
34
|
{
|
38
35
|
link: @url,
|
39
|
-
title:
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
title: raw["title"],
|
37
|
+
body: body,
|
38
|
+
excerpt: excerpt,
|
39
|
+
labels: raw["labels"],
|
40
|
+
user: raw['user'],
|
43
41
|
created_at: created_at.strftime("%I:%M%p - %d %b %y %Z"),
|
44
42
|
created_at_date: created_at.strftime("%F"),
|
45
43
|
created_at_time: created_at.strftime("%T"),
|
46
44
|
closed_at: closed_at&.strftime("%I:%M%p - %d %b %y %Z"),
|
47
45
|
closed_at_date: closed_at&.strftime("%F"),
|
48
46
|
closed_at_time: closed_at&.strftime("%T"),
|
49
|
-
closed_by:
|
50
|
-
avatar: "https://avatars1.githubusercontent.com/u/#{
|
47
|
+
closed_by: raw['closed_by'],
|
48
|
+
avatar: "https://avatars1.githubusercontent.com/u/#{raw['user']['id']}?v=2&s=96",
|
51
49
|
domain: "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}",
|
52
50
|
}
|
53
51
|
end
|
@@ -1,13 +1,18 @@
|
|
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 GithubPullRequestOnebox
|
6
8
|
include Engine
|
7
9
|
include LayoutSupport
|
8
10
|
include JSON
|
11
|
+
include Onebox::Mixins::GithubBody
|
12
|
+
|
13
|
+
GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/
|
9
14
|
|
10
|
-
matches_regexp
|
15
|
+
matches_regexp(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com(?:\/)?(?:.)*\/pull/)
|
11
16
|
always_https
|
12
17
|
|
13
18
|
def url
|
@@ -31,6 +36,9 @@ module Onebox
|
|
31
36
|
|
32
37
|
ulink = URI(link)
|
33
38
|
result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
|
39
|
+
|
40
|
+
result['body'], result['excerpt'] = compute_body(result['body'])
|
41
|
+
|
34
42
|
result
|
35
43
|
end
|
36
44
|
end
|
@@ -8,17 +8,21 @@ module Onebox
|
|
8
8
|
def self.git_regexp
|
9
9
|
/^https?:\/\/(www\.)?gitlab\.com.*\/blob\//
|
10
10
|
end
|
11
|
+
|
11
12
|
def self.onebox_name
|
12
13
|
"gitlabblob"
|
13
14
|
end
|
14
15
|
|
15
16
|
include Onebox::Mixins::GitBlobOnebox
|
17
|
+
|
16
18
|
def raw_regexp
|
17
19
|
/gitlab\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
|
18
20
|
end
|
21
|
+
|
19
22
|
def raw_template(m)
|
20
23
|
"https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
|
21
24
|
end
|
25
|
+
|
22
26
|
def title
|
23
27
|
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
|
24
28
|
end
|
@@ -5,7 +5,7 @@ module Onebox
|
|
5
5
|
class GoogleCalendarOnebox
|
6
6
|
include Engine
|
7
7
|
|
8
|
-
matches_regexp
|
8
|
+
matches_regexp(/^(https?:)?\/\/((www|calendar)\.google\.[\w.]{2,}|goo\.gl)\/calendar\/.+$/)
|
9
9
|
always_https
|
10
10
|
requires_iframe_origins "https://calendar.google.com"
|
11
11
|
|
@@ -19,19 +19,19 @@ module Onebox
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
matches_regexp
|
22
|
+
matches_regexp(/^(https?:)?\/\/(docs\.google\.com)\/(?<endpoint>(#{supported_endpoints.join('|')}))\/d\/((?<key>[\w-]*)).+$/)
|
23
23
|
always_https
|
24
24
|
|
25
25
|
protected
|
26
26
|
|
27
27
|
def data
|
28
28
|
og_data = get_og_data
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
{
|
30
|
+
link: link,
|
31
|
+
title: og_data[:title] || "Google #{shorttype.to_s.capitalize}",
|
32
|
+
description: Onebox::Helpers.truncate(og_data[:description], 250) || "This #{shorttype.to_s.chop.capitalize} is private",
|
33
|
+
type: shorttype
|
34
|
+
}
|
35
35
|
end
|
36
36
|
|
37
37
|
def doc_type
|
@@ -7,7 +7,7 @@ module Onebox
|
|
7
7
|
include StandardEmbed
|
8
8
|
include LayoutSupport
|
9
9
|
|
10
|
-
matches_regexp
|
10
|
+
matches_regexp(/^(https?:)?\/\/(drive\.google\.com)\/file\/d\/(?<key>[\w-]*)\/.+$/)
|
11
11
|
always_https
|
12
12
|
|
13
13
|
protected
|
@@ -18,12 +18,12 @@ module Onebox
|
|
18
18
|
title = "#{og_data.title} (video)" if og_data.type =~ /^video[\/\.]/
|
19
19
|
description = og_data.description || "Google Drive file."
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
{
|
22
|
+
link: link,
|
23
|
+
title: title,
|
24
|
+
description: Onebox::Helpers.truncate(description, 250),
|
25
|
+
image: og_data.image
|
26
|
+
}
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -22,7 +22,6 @@ module Onebox
|
|
22
22
|
end
|
23
23
|
|
24
24
|
always_https
|
25
|
-
|
26
25
|
requires_iframe_origins("https://maps.google.com", "https://google.com")
|
27
26
|
|
28
27
|
# Matches shortened Google Maps URLs
|
@@ -176,7 +175,6 @@ module Onebox
|
|
176
175
|
http.finish rescue nil
|
177
176
|
end
|
178
177
|
end
|
179
|
-
|
180
178
|
end
|
181
179
|
end
|
182
180
|
end
|
@@ -46,27 +46,27 @@ module Onebox
|
|
46
46
|
album_title = og.description.nil? ? og.title : "[#{og.description}] #{og.title}"
|
47
47
|
|
48
48
|
<<-HTML
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
</span>
|
49
|
+
<div class='onebox google-photos-album'>
|
50
|
+
<a href='#{escaped_url}' target='_blank' rel='noopener'>
|
51
|
+
<span class='outer-box' style='width:#{og.image_width}px'>
|
52
|
+
<span class='inner-box'>
|
53
|
+
<span class='album-title'>#{Onebox::Helpers.truncate(album_title, 80)}</span>
|
55
54
|
</span>
|
56
|
-
|
57
|
-
|
58
|
-
</
|
59
|
-
|
55
|
+
</span>
|
56
|
+
<img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
|
57
|
+
</a>
|
58
|
+
</div>
|
59
|
+
HTML
|
60
60
|
end
|
61
61
|
|
62
62
|
def image_html(og)
|
63
63
|
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
64
64
|
|
65
65
|
<<-HTML
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
<a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
|
67
|
+
<img src='#{og.get_secure_image}' #{og.title_attr} alt='Google Photos' height='#{og.image_height}' width='#{og.image_width}'>
|
68
|
+
</a>
|
69
|
+
HTML
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -11,24 +11,20 @@ module Onebox
|
|
11
11
|
MAX_DESCRIPTION_CHARS: 500
|
12
12
|
}
|
13
13
|
|
14
|
-
matches_regexp
|
14
|
+
matches_regexp(/^https?:\/\/play\.(?:(?:\w)+\.)?(google)\.com(?:\/)?\/store\/apps\//)
|
15
15
|
always_https
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def data
|
20
20
|
price = raw.css("meta[itemprop=price]").first["content"] rescue "Free"
|
21
|
-
|
21
|
+
{
|
22
22
|
link: link,
|
23
23
|
title: raw.css("meta[property='og:title']").first["content"].gsub(" - Apps on Google Play", ""),
|
24
24
|
image: ::Onebox::Helpers.normalize_url_for_output(raw.css("meta[property='og:image']").first["content"]),
|
25
25
|
description: raw.css("meta[name=description]").first["content"][0..DEFAULTS[:MAX_DESCRIPTION_CHARS]].chop + "...",
|
26
|
-
price: price
|
26
|
+
price: price == "0" ? "Free" : price
|
27
27
|
}
|
28
|
-
if result[:price] == "0"
|
29
|
-
result[:price] = "Free"
|
30
|
-
end
|
31
|
-
result
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
data/lib/onebox/engine/html.rb
CHANGED
@@ -11,10 +11,13 @@ module Onebox
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def raw
|
14
|
-
body_cacher = self.options[:body_cacher] if self.options
|
15
14
|
@raw ||= Onebox::Helpers.fetch_html_doc(url, http_params, body_cacher)
|
16
15
|
end
|
17
16
|
|
17
|
+
def body_cacher
|
18
|
+
self.options&.[](:body_cacher)
|
19
|
+
end
|
20
|
+
|
18
21
|
def html?
|
19
22
|
raw.respond_to(:css)
|
20
23
|
end
|
@@ -36,10 +36,10 @@ module Onebox
|
|
36
36
|
|
37
37
|
def get_oembed_url
|
38
38
|
if access_token != ''
|
39
|
-
|
39
|
+
"https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
|
40
40
|
else
|
41
41
|
# The following is officially deprecated by Instagram, but works in some limited circumstances.
|
42
|
-
|
42
|
+
"https://api.instagram.com/oembed/?url=#{clean_url}"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -14,7 +14,7 @@ module Onebox
|
|
14
14
|
og = get_opengraph
|
15
15
|
|
16
16
|
<<~HTML
|
17
|
-
<img src="#{og.image_secure_url}" width="#{og.video_width}" height="#{og.video_height}"
|
17
|
+
<img src="#{og.image_secure_url}" width="#{og.video_width}" height="#{og.video_height}">
|
18
18
|
HTML
|
19
19
|
end
|
20
20
|
|
@@ -22,11 +22,13 @@ module Onebox
|
|
22
22
|
og = get_opengraph
|
23
23
|
|
24
24
|
<<~HTML
|
25
|
-
<iframe
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
<iframe
|
26
|
+
src="#{og.video_secure_url}"
|
27
|
+
width="#{og.video_width}"
|
28
|
+
height="#{og.video_height}"
|
29
|
+
frameborder='0'
|
30
|
+
allowfullscreen
|
31
|
+
></iframe>
|
30
32
|
HTML
|
31
33
|
end
|
32
34
|
end
|
@@ -6,7 +6,7 @@ module Onebox
|
|
6
6
|
include Engine
|
7
7
|
include LayoutSupport
|
8
8
|
|
9
|
-
matches_regexp
|
9
|
+
matches_regexp(/^https?:\/\/(?:(?:\w)+\.)?(www.ncbi.nlm.nih)\.gov(?:\/)?\/pubmed\/\d+/)
|
10
10
|
|
11
11
|
private
|
12
12
|
|
@@ -35,7 +35,8 @@ module Onebox
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def data
|
38
|
-
xml = get_xml
|
38
|
+
xml = get_xml
|
39
|
+
|
39
40
|
{
|
40
41
|
title: xml.css("ArticleTitle").text,
|
41
42
|
authors: authors_of_xml(xml),
|
@@ -15,20 +15,20 @@ module Onebox
|
|
15
15
|
src = og.video_url.gsub("autostart=1", "")
|
16
16
|
|
17
17
|
<<-HTML
|
18
|
-
<iframe
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
<iframe
|
19
|
+
src="#{src}"
|
20
|
+
width="#{og.video_width}"
|
21
|
+
height="#{og.video_height}"
|
22
|
+
scrolling="no"
|
23
|
+
frameborder="0"
|
24
|
+
allowfullscreen
|
25
|
+
></iframe>
|
25
26
|
HTML
|
26
27
|
end
|
27
28
|
|
28
29
|
def placeholder_html
|
29
30
|
"<img src='#{get_opengraph.image}'>"
|
30
31
|
end
|
31
|
-
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -11,15 +11,16 @@ module Onebox
|
|
11
11
|
|
12
12
|
def to_html
|
13
13
|
<<-HTML
|
14
|
-
<iframe
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
<iframe
|
15
|
+
src="https://slides.com#{uri.path}/embed?style=light"
|
16
|
+
width="576"
|
17
|
+
height="420"
|
18
|
+
scrolling="no"
|
19
|
+
frameborder="0"
|
20
|
+
webkitallowfullscreen
|
21
|
+
mozallowfullscreen
|
22
|
+
allowfullscreen
|
23
|
+
></iframe>
|
23
24
|
HTML
|
24
25
|
end
|
25
26
|
|
@@ -27,7 +28,6 @@ module Onebox
|
|
27
28
|
escaped_src = ::Onebox::Helpers.normalize_url_for_output(raw[:image])
|
28
29
|
"<img src='#{escaped_src}'>"
|
29
30
|
end
|
30
|
-
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -37,7 +37,7 @@ module Onebox
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def data
|
40
|
-
return @data if @data
|
40
|
+
return @data if defined?(@data)
|
41
41
|
|
42
42
|
result = raw['items'][0]
|
43
43
|
if result
|
@@ -48,6 +48,7 @@ module Onebox
|
|
48
48
|
result['is_answer'] = result.key?('answer_id')
|
49
49
|
result['is_question'] = result.key?('question_id')
|
50
50
|
end
|
51
|
+
|
51
52
|
@data = result
|
52
53
|
end
|
53
54
|
end
|