onebox 2.2.12 → 2.2.13
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 +3 -1
- 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 +2 -3
- 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 +7 -4
- 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/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 +14 -13
- data/lib/onebox/file_type_finder.rb +0 -1
- data/lib/onebox/helpers.rb +2 -2
- 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/version.rb +1 -1
- data/templates/github/github_body.mustache +3 -0
- data/templates/githubissue.mustache +7 -9
- data/templates/githubpullrequest.mustache +4 -16
- metadata +4 -2
@@ -25,14 +25,16 @@ module Onebox
|
|
25
25
|
end
|
26
26
|
video_src = "https://player.vimeo.com/video/#{video_id}"
|
27
27
|
video_src = video_src.gsub('autoplay=1', '').chomp("?")
|
28
|
+
|
28
29
|
<<-HTML
|
29
|
-
<iframe
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
<iframe
|
31
|
+
width="#{WIDTH}"
|
32
|
+
height="#{HEIGHT}"
|
33
|
+
src="#{video_src}"
|
34
|
+
data-original-href="#{link}"
|
35
|
+
frameborder="0"
|
36
|
+
allowfullscreen
|
37
|
+
></iframe>
|
36
38
|
HTML
|
37
39
|
end
|
38
40
|
|
@@ -7,7 +7,7 @@ module Onebox
|
|
7
7
|
include LayoutSupport
|
8
8
|
include JSON
|
9
9
|
|
10
|
-
matches_regexp
|
10
|
+
matches_regexp(/^https?:\/\/commons\.wikimedia\.org\/wiki\/(File:.+)/)
|
11
11
|
always_https
|
12
12
|
|
13
13
|
def self.priority
|
@@ -38,7 +38,6 @@ module Onebox
|
|
38
38
|
thumbnail: first_page['imageinfo'].first['thumburl']
|
39
39
|
}
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -16,10 +16,10 @@ module Onebox
|
|
16
16
|
paras = []
|
17
17
|
text = ""
|
18
18
|
|
19
|
-
# Detect section Hash in the url and retrive the related paragraphs.
|
19
|
+
# Detect section Hash in the url and retrive the related paragraphs. if no hash provided the first few paragraphs will be used
|
20
20
|
# Author Lidlanca
|
21
21
|
# Date 9/8/2014
|
22
|
-
if (m_url_hash = @url.match(/#([^\/?]+)/)) #extract url hash
|
22
|
+
if (m_url_hash = @url.match(/#([^\/?]+)/)) # extract url hash
|
23
23
|
m_url_hash_name = m_url_hash[1]
|
24
24
|
end
|
25
25
|
|
@@ -27,17 +27,17 @@ module Onebox
|
|
27
27
|
section_header_title = raw.xpath("//span[@id='#{m_url_hash_name}']")
|
28
28
|
|
29
29
|
if section_header_title.empty?
|
30
|
-
paras = raw.search("p") #default get all the paras
|
30
|
+
paras = raw.search("p") # default get all the paras
|
31
31
|
else
|
32
32
|
section_title_text = section_header_title.inner_text
|
33
|
-
section_header = section_header_title[0].parent #parent element of the section span element should be an <h3> node
|
33
|
+
section_header = section_header_title[0].parent # parent element of the section span element should be an <h3> node
|
34
34
|
cur_element = section_header
|
35
35
|
|
36
|
-
# p|text|div covers the general case. We assume presence of
|
36
|
+
# p|text|div covers the general case. We assume presence of at least 1 P node. if section has no P node we may end up with a P node from the next section.
|
37
37
|
# div tag is commonly used as an assets wraper in an article section. often as the first element holding an image.
|
38
38
|
# ul support will imporve the output generated for a section with a list as the main content (for example: an Author Bibliography, A musician Discography, etc)
|
39
39
|
first_p_found = nil
|
40
|
-
while (((next_sibling = cur_element.next_sibling).name =~ /p|text|div|ul/) || first_p_found.nil?) do #from section header get the next sibling until it is a breaker tag
|
40
|
+
while (((next_sibling = cur_element.next_sibling).name =~ /p|text|div|ul/) || first_p_found.nil?) do # from section header get the next sibling until it is a breaker tag
|
41
41
|
cur_element = next_sibling
|
42
42
|
if (cur_element.name == "p" || cur_element.name == "ul") #we treat a list as we detect a p to avoid showing
|
43
43
|
first_p_found = true
|
@@ -46,7 +46,7 @@ module Onebox
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
else # no hash found in url
|
49
|
-
paras = raw.search("p") #default get all the paras
|
49
|
+
paras = raw.search("p") # default get all the paras
|
50
50
|
end
|
51
51
|
|
52
52
|
unless paras.empty?
|
@@ -55,7 +55,7 @@ module Onebox
|
|
55
55
|
break if cnt >= paras.size
|
56
56
|
text += " " unless cnt == 0
|
57
57
|
|
58
|
-
if paras[cnt].name == "ul" #Handle UL tag. Generate a textual ordered list (1.item | 2.item | 3.item).
|
58
|
+
if paras[cnt].name == "ul" # Handle UL tag. Generate a textual ordered list (1.item | 2.item | 3.item). Unfortunately no newline allowed in output
|
59
59
|
li_index = 1
|
60
60
|
list_items = []
|
61
61
|
paras[cnt].children.css("li").each { |li| list_items.push "#{li_index}." + li.inner_text ; li_index += 1 }
|
@@ -69,13 +69,17 @@ module Onebox
|
|
69
69
|
cnt += 1
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
72
73
|
text = "#{text[0..Onebox::LayoutSupport.max_text]}..." if text.length > Onebox::LayoutSupport.max_text
|
74
|
+
|
73
75
|
result = {
|
74
76
|
link: link,
|
75
77
|
title: raw.css("html body h1").inner_text + (section_title_text ? " | " + section_title_text : ""), #if a section sub title exists add it to the main article title
|
76
78
|
description: text
|
77
79
|
}
|
80
|
+
|
78
81
|
img = raw.css(".image img")
|
82
|
+
|
79
83
|
if img && img.size > 0
|
80
84
|
img.each do |i|
|
81
85
|
src = i["src"]
|
@@ -21,12 +21,13 @@ module Onebox
|
|
21
21
|
|
22
22
|
def to_html
|
23
23
|
<<~HTML
|
24
|
-
<iframe
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
<iframe
|
25
|
+
src="https://player.youku.com/embed/#{video_id}"
|
26
|
+
width="640"
|
27
|
+
height="430"
|
28
|
+
frameborder='0'
|
29
|
+
allowfullscreen
|
30
|
+
></iframe>
|
30
31
|
HTML
|
31
32
|
end
|
32
33
|
|
@@ -35,7 +36,6 @@ module Onebox
|
|
35
36
|
def uri
|
36
37
|
@_uri ||= URI(@url)
|
37
38
|
end
|
38
|
-
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -51,21 +51,23 @@ module Onebox
|
|
51
51
|
def to_html
|
52
52
|
if video_id
|
53
53
|
<<-HTML
|
54
|
-
<iframe
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
<iframe
|
55
|
+
src="https://www.youtube.com/embed/#{video_id}?#{embed_params}"
|
56
|
+
width="#{WIDTH}"
|
57
|
+
height="#{HEIGHT}"
|
58
|
+
frameborder="0"
|
59
|
+
allowfullscreen
|
60
|
+
></iframe>
|
60
61
|
HTML
|
61
62
|
elsif list_id
|
62
63
|
<<-HTML
|
63
|
-
<iframe
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
<iframe
|
65
|
+
src="https://www.youtube.com/embed/videoseries?list=#{list_id}&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1"
|
66
|
+
width="#{WIDTH}"
|
67
|
+
height="#{HEIGHT}"
|
68
|
+
frameborder="0"
|
69
|
+
allowfullscreen
|
70
|
+
></iframe>
|
69
71
|
HTML
|
70
72
|
else
|
71
73
|
# for channel pages
|
@@ -166,7 +168,6 @@ module Onebox
|
|
166
168
|
rescue
|
167
169
|
{}
|
168
170
|
end
|
169
|
-
|
170
171
|
end
|
171
172
|
end
|
172
173
|
end
|
data/lib/onebox/helpers.rb
CHANGED
@@ -127,10 +127,10 @@ module Onebox
|
|
127
127
|
|
128
128
|
http.request_head([uri.path, uri.query].join("?")) do |response|
|
129
129
|
code = response.code.to_i
|
130
|
-
unless code === 200 || Onebox::Helpers.blank?(response.
|
130
|
+
unless code === 200 || Onebox::Helpers.blank?(response.content_length)
|
131
131
|
return nil
|
132
132
|
end
|
133
|
-
return response.
|
133
|
+
return response.content_length
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -33,6 +33,10 @@ module Onebox
|
|
33
33
|
|
34
34
|
self.options = DEFAULTS
|
35
35
|
|
36
|
+
@selected_lines_array = nil
|
37
|
+
@selected_one_liner = 0
|
38
|
+
@model_file = nil
|
39
|
+
|
36
40
|
# Define constant after merging options set in Onebox.options
|
37
41
|
# We can define constant automatically.
|
38
42
|
options.each_pair do |constant_name, value|
|
@@ -47,8 +51,6 @@ module Onebox
|
|
47
51
|
end
|
48
52
|
|
49
53
|
private
|
50
|
-
@selected_lines_array = nil
|
51
|
-
@selected_one_liner = 0
|
52
54
|
|
53
55
|
def calc_range(m, contents_lines_size)
|
54
56
|
truncated = false
|
@@ -150,7 +152,7 @@ module Onebox
|
|
150
152
|
end
|
151
153
|
|
152
154
|
def raw
|
153
|
-
return @raw if @raw
|
155
|
+
return @raw if defined?(@raw)
|
154
156
|
|
155
157
|
m = @url.match(self.raw_regexp)
|
156
158
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Onebox
|
4
|
+
module Mixins
|
5
|
+
module GithubBody
|
6
|
+
def self.included(klass)
|
7
|
+
klass.include(Onebox::Engine)
|
8
|
+
klass.include(InstanceMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/
|
13
|
+
MAX_BODY_LENGTH = 80
|
14
|
+
def compute_body(body)
|
15
|
+
body = body.dup
|
16
|
+
excerpt = nil
|
17
|
+
|
18
|
+
body = (body || '').gsub(GITHUB_COMMENT_REGEX, '')
|
19
|
+
body = body.length > 0 ? body : nil
|
20
|
+
if body && body.length > MAX_BODY_LENGTH
|
21
|
+
excerpt = body[MAX_BODY_LENGTH..body.length].rstrip
|
22
|
+
body = body[0..MAX_BODY_LENGTH - 1]
|
23
|
+
end
|
24
|
+
|
25
|
+
[body, excerpt]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/onebox/preview.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module Onebox
|
4
4
|
class Preview
|
5
|
-
|
6
5
|
# see https://bugs.ruby-lang.org/issues/14688
|
7
6
|
client_exception = defined?(Net::HTTPClientException) ? Net::HTTPClientException : Net::HTTPServerException
|
8
7
|
WEB_EXCEPTIONS ||= [client_exception, OpenURI::HTTPError, Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED]
|
@@ -85,7 +84,7 @@ module Onebox
|
|
85
84
|
|
86
85
|
def engine
|
87
86
|
return nil unless @engine_class
|
88
|
-
return @engine if @engine
|
87
|
+
return @engine if defined?(@engine)
|
89
88
|
|
90
89
|
@engine = @engine_class.new(@url)
|
91
90
|
@engine.options = @options
|
data/lib/onebox/version.rb
CHANGED
@@ -0,0 +1,3 @@
|
|
1
|
+
{{#body}}
|
2
|
+
<p class="github-body-container">{{body}}{{#excerpt}}<span class="show-more-container"><a href="{{html_url}}" target="_blank" rel="noopener" class="show-more">…</a>{{/excerpt}}</span>{{#excerpt}}<span class="excerpt hidden">{{excerpt}}</span>{{/excerpt}}</p>
|
3
|
+
{{/body}}
|
@@ -26,15 +26,13 @@
|
|
26
26
|
</a>
|
27
27
|
</div>
|
28
28
|
</div>
|
29
|
-
</div>
|
30
|
-
</div>
|
31
29
|
|
32
|
-
|
33
|
-
<p class='github-content'>{{content}}</p>
|
34
|
-
</div>
|
30
|
+
{{> github/github_body}}
|
35
31
|
|
36
|
-
<div class='labels'>
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
<div class='labels'>
|
33
|
+
{{#labels}}
|
34
|
+
<span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">{{name}}</span>
|
35
|
+
{{/labels}}
|
36
|
+
</div>
|
37
|
+
</div>
|
40
38
|
</div>
|
@@ -4,22 +4,9 @@
|
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="github-info-container">
|
7
|
-
|
8
|
-
<
|
9
|
-
|
10
|
-
</h4>
|
11
|
-
{{/body}}
|
12
|
-
|
13
|
-
{{#body}}
|
14
|
-
<details class="onebox-details">
|
15
|
-
<summary class="onebox-details-summary">
|
16
|
-
<h4>
|
17
|
-
<a href="{{html_url}}" target="_blank" rel="noopener">{{title}}</a>
|
18
|
-
</h4>
|
19
|
-
</summary>
|
20
|
-
<p class="onebox-details-body">{{body}}</p>
|
21
|
-
</details>
|
22
|
-
{{/body}}
|
7
|
+
<h4>
|
8
|
+
<a href="{{html_url}}" target="_blank" rel="noopener">{{title}}</a>
|
9
|
+
</h4>
|
23
10
|
|
24
11
|
<div class="branches">
|
25
12
|
<code>{{base.label}}</code> ← <code>{{head.label}}</code>
|
@@ -45,5 +32,6 @@
|
|
45
32
|
</div>
|
46
33
|
</div>
|
47
34
|
|
35
|
+
{{> github/github_body}}
|
48
36
|
</div>
|
49
37
|
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joanna Zeta
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-04-
|
13
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -367,6 +367,7 @@ files:
|
|
367
367
|
- lib/onebox/layout_support.rb
|
368
368
|
- lib/onebox/matcher.rb
|
369
369
|
- lib/onebox/mixins/git_blob_onebox.rb
|
370
|
+
- lib/onebox/mixins/github_body.rb
|
370
371
|
- lib/onebox/mixins/twitch_onebox.rb
|
371
372
|
- lib/onebox/oembed.rb
|
372
373
|
- lib/onebox/open_graph.rb
|
@@ -382,6 +383,7 @@ files:
|
|
382
383
|
- templates/_layout.mustache
|
383
384
|
- templates/allowlistedgeneric.mustache
|
384
385
|
- templates/amazon.mustache
|
386
|
+
- templates/github/github_body.mustache
|
385
387
|
- templates/githubblob.mustache
|
386
388
|
- templates/githubcommit.mustache
|
387
389
|
- templates/githubfolder.mustache
|