onebox 2.1.7 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9a1e5a4239bdcf5a170e23cb70ae17f581cd25de8c6b72eb911d953119fb8cb
4
- data.tar.gz: 80057c1f0667b807e1e5be53ff283dabeabe64aa3c3f53d1c63658346e7d12ab
3
+ metadata.gz: 817b81480e38b1a133342d89f83991cd0e94217581ddb74c6275c6631c7285bf
4
+ data.tar.gz: 545e95966e368c2b36a9792dd99934ec609635e19d95bb02ef1dd1fbcd51c5f6
5
5
  SHA512:
6
- metadata.gz: 94a0e7ecc496f75f5f59f40701247fba1bff1068a21c91773e43285c3bf83eadd945ecdd910a8becb454870f5c790baed7626e5cd7d2fe7a6951e7da5fb3e701
7
- data.tar.gz: 1ad163ff7cfad65008902d27244bd74a9d84e2e49d8600c9ed6f48e74f0fff4d8e77250b36cb4c03e68fdf6f29ab67a8e3e1238b7645156f3f93269f94548329
6
+ metadata.gz: fc0ea7daff3babaa77cebf9e5e00161877a86106d15b1a2d4e1b1e56f1e4ba9ebfd6e3666a991d420e4ea71180dc8fcaf2bafc0ac659934399706462c1e45d69
7
+ data.tar.gz: f509adf0a3ad1d557700a690bfb9b922ec9c181b68cf6ab61134394ee70c8ee4487d64faa863262a28cd795ed14e39bc774521572551c719faa39a1acc208a3e
@@ -286,7 +286,7 @@ module Onebox
286
286
  return image_html if is_image?
287
287
  return embedded_html if is_embedded?
288
288
  return card_html if is_card?
289
- return article_html if has_text?
289
+ return article_html if (has_text? || is_image_article?)
290
290
  end
291
291
 
292
292
  def is_card?
@@ -301,9 +301,17 @@ module Onebox
301
301
  end
302
302
 
303
303
  def has_text?
304
+ has_title? && !Onebox::Helpers.blank?(data[:description])
305
+ end
306
+
307
+ def has_title?
304
308
  !Onebox::Helpers.blank?(data[:title])
305
309
  end
306
310
 
311
+ def is_image_article?
312
+ has_title? && has_image?
313
+ end
314
+
307
315
  def is_image?
308
316
  data[:type] =~ /photo|image/ &&
309
317
  data[:type] !~ /photostream/ &&
@@ -7,9 +7,14 @@ module Onebox
7
7
  include StandardEmbed
8
8
  include LayoutSupport
9
9
 
10
- matches_regexp Regexp.new(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com[\:\d]*(\/\w*){2}\/tree/)
10
+ matches_regexp Regexp.new(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com[\:\d]*(\/[^\/]+){2}/)
11
11
  always_https
12
12
 
13
+ def self.priority
14
+ # This engine should have lower priority than the other Github engines
15
+ 150
16
+ end
17
+
13
18
  private
14
19
 
15
20
  def data
@@ -20,11 +25,29 @@ module Onebox
20
25
  display_path = extract_path(og.url, max_length)
21
26
  display_description = clean_description(og.description, og.title, max_length)
22
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
+
23
47
  {
24
- link: og.url,
25
- path_link: url,
48
+ link: url,
26
49
  image: og.image,
27
- title: og.title,
50
+ title: Onebox::Helpers.truncate(title, 250),
28
51
  path: display_path,
29
52
  description: display_description,
30
53
  favicon: get_favicon
@@ -34,6 +57,9 @@ module Onebox
34
57
  def extract_path(root, max_length)
35
58
  path = url.split('#')[0].split('?')[0]
36
59
  path = path["#{root}/tree/".length..-1]
60
+
61
+ return unless path
62
+
37
63
  path.length > max_length ? path[-max_length..-1] : path
38
64
  end
39
65
 
@@ -7,11 +7,11 @@ module Onebox
7
7
  include StandardEmbed
8
8
  include LayoutSupport
9
9
 
10
- matches_regexp(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/?(?:.*)\/p\/[a-zA-Z\d_-]+/)
10
+ matches_regexp(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/?(?:.*)\/(?:p|tv)\/[a-zA-Z\d_-]+/)
11
11
  always_https
12
12
 
13
13
  def clean_url
14
- url.scan(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/?(?:.*)\/p\/[a-zA-Z\d_-]+/).flatten.first
14
+ url.scan(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/?(?:.*)\/(?:p|tv)\/[a-zA-Z\d_-]+/).flatten.first
15
15
  end
16
16
 
17
17
  def data
@@ -8,6 +8,7 @@ module Onebox
8
8
 
9
9
  matches_regexp(/https?:\/\/(.+)?simplecast.com\/(episodes|s)\/.*/)
10
10
  always_https
11
+ requires_iframe_origins("https://embed.simplecast.com")
11
12
 
12
13
  def to_html
13
14
  get_oembed.html
@@ -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
- if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{uri.host}#{uri.path}"
39
- response = (fetch_response(canonical_link, nil, nil, headers) rescue nil)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "2.1.7"
4
+ VERSION = "2.2.2"
5
5
  end
@@ -3,7 +3,7 @@
3
3
  <h3><a href='{{link}}' target="_blank" rel="noopener">{{title}}</a></h3>
4
4
 
5
5
  {{#path}}
6
- <p><a href='{{path_link}}' target="_blank" rel="noopener">{{path}}</a></p>
6
+ <p><a href='{{link}}' target="_blank" rel="noopener">{{path}}</a></p>
7
7
  {{/path}}
8
8
 
9
9
  {{#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.7
4
+ version: 2.2.2
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-11-20 00:00:00.000000000 Z
13
+ date: 2021-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable