onebox 2.1.3 → 2.1.8
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/lib/onebox/engine.rb +3 -0
- data/lib/onebox/engine/allowlisted_generic_onebox.rb +11 -2
- data/lib/onebox/engine/github_folder_onebox.rb +79 -0
- data/lib/onebox/engine/imgur_onebox.rb +1 -1
- data/lib/onebox/engine/instagram_onebox.rb +15 -3
- data/lib/onebox/engine/standard_embed.rb +1 -1
- data/lib/onebox/helpers.rb +5 -3
- data/lib/onebox/preview.rb +11 -1
- data/lib/onebox/version.rb +1 -1
- data/onebox.gemspec +1 -1
- data/templates/githubfolder.mustache +11 -0
- data/templates/instagram.mustache +3 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9885ad2362b97a26732cf64fef583674c58250648f403627aef33e87687f2bb
|
4
|
+
data.tar.gz: 7678e338a3eb5276e53e3f673d230dc67f2b1cdf395adb339f09162f96e4c058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fe261d1536790c511b437afcf5e6aff632d21f3c4ef47c96c4a3adbf31c6b8f2b07e186323ddb4858a1c37c23d651bd96deeb49feb493c4064c11f2ba5d0d92
|
7
|
+
data.tar.gz: e46b1a057f9f6b351dd96eed98dbcee7209fe5ca9c4c247dbeb715988851a3ac99875e174022f60f08a5848e226f277562be131085dcbfa667544de41da17cd0
|
data/lib/onebox/engine.rb
CHANGED
@@ -30,6 +30,7 @@ module Onebox
|
|
30
30
|
|
31
31
|
attr_reader :url, :uri
|
32
32
|
attr_reader :timeout
|
33
|
+
attr :errors
|
33
34
|
|
34
35
|
DEFAULT = {}
|
35
36
|
def options
|
@@ -44,6 +45,7 @@ module Onebox
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def initialize(link, timeout = nil)
|
48
|
+
@errors = {}
|
47
49
|
@options = DEFAULT
|
48
50
|
class_name = self.class.name.split("::").last.to_s
|
49
51
|
|
@@ -150,6 +152,7 @@ require_relative "engine/amazon_onebox"
|
|
150
152
|
require_relative "engine/github_issue_onebox"
|
151
153
|
require_relative "engine/github_blob_onebox"
|
152
154
|
require_relative "engine/github_commit_onebox"
|
155
|
+
require_relative "engine/github_folder_onebox"
|
153
156
|
require_relative "engine/github_gist_onebox"
|
154
157
|
require_relative "engine/github_pullrequest_onebox"
|
155
158
|
require_relative "engine/google_calendar_onebox"
|
@@ -256,6 +256,15 @@ module Onebox
|
|
256
256
|
d[:data_1] = Onebox::Helpers.truncate("#{d[:price_currency].strip} #{d[:price_amount].strip}")
|
257
257
|
end
|
258
258
|
|
259
|
+
skip_missing_tags = [:video]
|
260
|
+
d.each do |k, v|
|
261
|
+
next if skip_missing_tags.include?(k)
|
262
|
+
if v == nil || v == ''
|
263
|
+
errors[k] ||= []
|
264
|
+
errors[k] << 'is blank'
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
259
268
|
d
|
260
269
|
end
|
261
270
|
end
|
@@ -316,7 +325,7 @@ module Onebox
|
|
316
325
|
return true if AllowlistedGenericOnebox.html_providers.include?(data[:provider_name])
|
317
326
|
return false unless data[:html]["iframe"]
|
318
327
|
|
319
|
-
fragment = Nokogiri::
|
328
|
+
fragment = Nokogiri::HTML5::fragment(data[:html])
|
320
329
|
src = fragment.at_css('iframe')&.[]("src")
|
321
330
|
options[:allowed_iframe_regexes]&.any? { |r| src =~ r }
|
322
331
|
end
|
@@ -367,7 +376,7 @@ module Onebox
|
|
367
376
|
end
|
368
377
|
|
369
378
|
def embedded_html
|
370
|
-
fragment = Nokogiri::
|
379
|
+
fragment = Nokogiri::HTML5::fragment(data[:html])
|
371
380
|
fragment.css("img").each { |img| img["class"] = "thumbnail" }
|
372
381
|
if iframe = fragment.at_css("iframe")
|
373
382
|
iframe.remove_attribute("style")
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Onebox
|
4
|
+
module Engine
|
5
|
+
class GithubFolderOnebox
|
6
|
+
include Engine
|
7
|
+
include StandardEmbed
|
8
|
+
include LayoutSupport
|
9
|
+
|
10
|
+
matches_regexp Regexp.new(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com[\:\d]*(\/[^\/]+){2}/)
|
11
|
+
always_https
|
12
|
+
|
13
|
+
def self.priority
|
14
|
+
# This engine should have lower priority than the other Github engines
|
15
|
+
150
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def data
|
21
|
+
og = get_opengraph
|
22
|
+
|
23
|
+
max_length = 250
|
24
|
+
|
25
|
+
display_path = extract_path(og.url, max_length)
|
26
|
+
display_description = clean_description(og.description, og.title, max_length)
|
27
|
+
|
28
|
+
title = og.title
|
29
|
+
|
30
|
+
fragment = Addressable::URI.parse(url).fragment
|
31
|
+
if fragment
|
32
|
+
fragment = Addressable::URI.unencode(fragment)
|
33
|
+
|
34
|
+
if html_doc.css('.Box.md')
|
35
|
+
# For links to markdown docs
|
36
|
+
node = html_doc.css('a.anchor').find { |n| n['href'] == "##{fragment}" }
|
37
|
+
subtitle = node&.parent&.text
|
38
|
+
elsif html_doc.css('.Box.rdoc')
|
39
|
+
# For links to rdoc docs
|
40
|
+
node = html_doc.css('h3').find { |n| n['id'] == "user-content-#{fragment.downcase}" }
|
41
|
+
subtitle = node&.css('text()')&.first&.text
|
42
|
+
end
|
43
|
+
|
44
|
+
title = "#{title} - #{subtitle}" if subtitle
|
45
|
+
end
|
46
|
+
|
47
|
+
{
|
48
|
+
link: og.url,
|
49
|
+
path_link: url,
|
50
|
+
image: og.image,
|
51
|
+
title: Onebox::Helpers.truncate(title, 250),
|
52
|
+
path: display_path,
|
53
|
+
description: display_description,
|
54
|
+
favicon: get_favicon
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def extract_path(root, max_length)
|
59
|
+
path = url.split('#')[0].split('?')[0]
|
60
|
+
path = path["#{root}/tree/".length..-1]
|
61
|
+
|
62
|
+
return unless path
|
63
|
+
|
64
|
+
path.length > max_length ? path[-max_length..-1] : path
|
65
|
+
end
|
66
|
+
|
67
|
+
def clean_description(description, title, max_length)
|
68
|
+
return unless description
|
69
|
+
|
70
|
+
desc_end = " - #{title}"
|
71
|
+
if description[-desc_end.length..-1] == desc_end
|
72
|
+
description = description[0...-desc_end.length]
|
73
|
+
end
|
74
|
+
|
75
|
+
Onebox::Helpers.truncate(description, max_length)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -58,7 +58,7 @@ module Onebox
|
|
58
58
|
|
59
59
|
<<-HTML
|
60
60
|
<a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
|
61
|
-
<img src='#{og.get_secure_image}' #{og.title_attr} alt='Imgur'
|
61
|
+
<img src='#{og.get_secure_image.chomp("?fb")}' #{og.title_attr} alt='Imgur'>
|
62
62
|
</a>
|
63
63
|
HTML
|
64
64
|
end
|
@@ -16,19 +16,31 @@ module Onebox
|
|
16
16
|
|
17
17
|
def data
|
18
18
|
oembed = get_oembed
|
19
|
+
raise "No oEmbed data found. Ensure 'facebook_app_access_token' is valid" if oembed.data.empty?
|
20
|
+
|
19
21
|
permalink = clean_url.gsub("/#{oembed.author_name}/", "/")
|
20
22
|
|
21
23
|
{ link: permalink,
|
22
24
|
title: "@#{oembed.author_name}",
|
23
|
-
image:
|
24
|
-
description: Onebox::Helpers.truncate(oembed.title, 250)
|
25
|
+
image: oembed.thumbnail_url,
|
26
|
+
description: Onebox::Helpers.truncate(oembed.title, 250),
|
25
27
|
}
|
28
|
+
|
26
29
|
end
|
27
30
|
|
28
31
|
protected
|
29
32
|
|
33
|
+
def access_token
|
34
|
+
(options[:facebook_app_access_token] || Onebox.options.facebook_app_access_token).to_s
|
35
|
+
end
|
36
|
+
|
30
37
|
def get_oembed_url
|
31
|
-
|
38
|
+
if access_token != ''
|
39
|
+
oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
|
40
|
+
else
|
41
|
+
# The following is officially deprecated by Instagram, but works in some limited circumstances.
|
42
|
+
oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
|
43
|
+
end
|
32
44
|
end
|
33
45
|
end
|
34
46
|
end
|
@@ -91,7 +91,7 @@ module Onebox
|
|
91
91
|
html_doc.css('meta').each do |m|
|
92
92
|
if (m["property"] && m["property"][/^twitter:(.+)$/i]) || (m["name"] && m["name"][/^twitter:(.+)$/i])
|
93
93
|
value = (m["content"] || m["value"]).to_s
|
94
|
-
twitter[$1.tr('-:' , '_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
|
94
|
+
twitter[$1.tr('-:' , '_').to_sym] ||= value unless (Onebox::Helpers::blank?(value) || value == "0 minutes")
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
data/lib/onebox/helpers.rb
CHANGED
@@ -27,7 +27,7 @@ module Onebox
|
|
27
27
|
def self.fetch_html_doc(url, headers = nil)
|
28
28
|
response = (fetch_response(url, nil, nil, headers) rescue nil)
|
29
29
|
doc = Nokogiri::HTML(response)
|
30
|
-
uri = URI(url)
|
30
|
+
uri = Addressable::URI.parse(url)
|
31
31
|
|
32
32
|
ignore_canonical_tag = doc.at('meta[property="og:ignore_canonical"]')
|
33
33
|
should_ignore_canonical = IGNORE_CANONICAL_DOMAINS.map { |hostname| uri.hostname.match?(hostname) }.any?
|
@@ -35,8 +35,9 @@ module Onebox
|
|
35
35
|
unless (ignore_canonical_tag && ignore_canonical_tag['content'].to_s == 'true') || should_ignore_canonical
|
36
36
|
# prefer canonical link
|
37
37
|
canonical_link = doc.at('//link[@rel="canonical"]/@href')
|
38
|
-
|
39
|
-
|
38
|
+
canonical_uri = Addressable::URI.parse(canonical_link)
|
39
|
+
if canonical_link && "#{canonical_uri.host}#{canonical_uri.path}" != "#{uri.host}#{uri.path}"
|
40
|
+
response = (fetch_response(canonical_uri.to_s, nil, nil, headers) rescue nil)
|
40
41
|
doc = Nokogiri::HTML(response) if response
|
41
42
|
end
|
42
43
|
end
|
@@ -156,6 +157,7 @@ module Onebox
|
|
156
157
|
end
|
157
158
|
|
158
159
|
def self.truncate(string, length = 50)
|
160
|
+
return string if string.nil?
|
159
161
|
string.size > length ? string[0...(string.rindex(" ", length) || length)] + "..." : string
|
160
162
|
end
|
161
163
|
|
data/lib/onebox/preview.rb
CHANGED
@@ -31,6 +31,16 @@ module Onebox
|
|
31
31
|
""
|
32
32
|
end
|
33
33
|
|
34
|
+
def errors
|
35
|
+
return {} unless engine
|
36
|
+
engine.errors
|
37
|
+
end
|
38
|
+
|
39
|
+
def data
|
40
|
+
return {} unless engine
|
41
|
+
engine.data
|
42
|
+
end
|
43
|
+
|
34
44
|
def options
|
35
45
|
OpenStruct.new(@options)
|
36
46
|
end
|
@@ -45,7 +55,7 @@ module Onebox
|
|
45
55
|
return "" unless html
|
46
56
|
|
47
57
|
if @options[:max_width]
|
48
|
-
doc = Nokogiri::
|
58
|
+
doc = Nokogiri::HTML5::fragment(html)
|
49
59
|
if doc
|
50
60
|
doc.css('[width]').each do |e|
|
51
61
|
width = e['width'].to_i
|
data/lib/onebox/version.rb
CHANGED
data/onebox.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency 'fakeweb', '~> 1.3'
|
34
34
|
spec.add_development_dependency 'pry', '~> 0.10'
|
35
35
|
spec.add_development_dependency 'mocha', '~> 1.1'
|
36
|
-
spec.add_development_dependency 'rubocop-discourse', '~> 2.
|
36
|
+
spec.add_development_dependency 'rubocop-discourse', '~> 2.4.0'
|
37
37
|
spec.add_development_dependency 'twitter', '~> 4.8'
|
38
38
|
spec.add_development_dependency 'guard-rspec', '~> 4.2.8'
|
39
39
|
spec.add_development_dependency 'sinatra', '~> 1.4'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
|
2
|
+
|
3
|
+
<h3><a href='{{link}}' target="_blank" rel="noopener">{{title}}</a></h3>
|
4
|
+
|
5
|
+
{{#path}}
|
6
|
+
<p><a href='{{path_link}}' target="_blank" rel="noopener">{{path}}</a></p>
|
7
|
+
{{/path}}
|
8
|
+
|
9
|
+
{{#description}}
|
10
|
+
<p><span class="label1">{{description}}</span></p>
|
11
|
+
{{/description}}
|
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.1.
|
4
|
+
version: 2.1.8
|
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: 2020-
|
13
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -186,14 +186,14 @@ dependencies:
|
|
186
186
|
requirements:
|
187
187
|
- - "~>"
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: 2.
|
189
|
+
version: 2.4.0
|
190
190
|
type: :development
|
191
191
|
prerelease: false
|
192
192
|
version_requirements: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
194
|
- - "~>"
|
195
195
|
- !ruby/object:Gem::Version
|
196
|
-
version: 2.
|
196
|
+
version: 2.4.0
|
197
197
|
- !ruby/object:Gem::Dependency
|
198
198
|
name: twitter
|
199
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -316,6 +316,7 @@ files:
|
|
316
316
|
- lib/onebox/engine/giphy_onebox.rb
|
317
317
|
- lib/onebox/engine/github_blob_onebox.rb
|
318
318
|
- lib/onebox/engine/github_commit_onebox.rb
|
319
|
+
- lib/onebox/engine/github_folder_onebox.rb
|
319
320
|
- lib/onebox/engine/github_gist_onebox.rb
|
320
321
|
- lib/onebox/engine/github_issue_onebox.rb
|
321
322
|
- lib/onebox/engine/github_pullrequest_onebox.rb
|
@@ -383,6 +384,7 @@ files:
|
|
383
384
|
- templates/amazon.mustache
|
384
385
|
- templates/githubblob.mustache
|
385
386
|
- templates/githubcommit.mustache
|
387
|
+
- templates/githubfolder.mustache
|
386
388
|
- templates/githubgist.mustache
|
387
389
|
- templates/githubissue.mustache
|
388
390
|
- templates/githubpullrequest.mustache
|