onebox 2.1.7 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9a1e5a4239bdcf5a170e23cb70ae17f581cd25de8c6b72eb911d953119fb8cb
4
- data.tar.gz: 80057c1f0667b807e1e5be53ff283dabeabe64aa3c3f53d1c63658346e7d12ab
3
+ metadata.gz: b9885ad2362b97a26732cf64fef583674c58250648f403627aef33e87687f2bb
4
+ data.tar.gz: 7678e338a3eb5276e53e3f673d230dc67f2b1cdf395adb339f09162f96e4c058
5
5
  SHA512:
6
- metadata.gz: 94a0e7ecc496f75f5f59f40701247fba1bff1068a21c91773e43285c3bf83eadd945ecdd910a8becb454870f5c790baed7626e5cd7d2fe7a6951e7da5fb3e701
7
- data.tar.gz: 1ad163ff7cfad65008902d27244bd74a9d84e2e49d8600c9ed6f48e74f0fff4d8e77250b36cb4c03e68fdf6f29ab67a8e3e1238b7645156f3f93269f94548329
6
+ metadata.gz: 8fe261d1536790c511b437afcf5e6aff632d21f3c4ef47c96c4a3adbf31c6b8f2b07e186323ddb4858a1c37c23d651bd96deeb49feb493c4064c11f2ba5d0d92
7
+ data.tar.gz: e46b1a057f9f6b351dd96eed98dbcee7209fe5ca9c4c247dbeb715988851a3ac99875e174022f60f08a5848e226f277562be131085dcbfa667544de41da17cd0
@@ -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,30 @@ 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
48
  link: og.url,
25
49
  path_link: url,
26
50
  image: og.image,
27
- title: og.title,
51
+ title: Onebox::Helpers.truncate(title, 250),
28
52
  path: display_path,
29
53
  description: display_description,
30
54
  favicon: get_favicon
@@ -34,6 +58,9 @@ module Onebox
34
58
  def extract_path(root, max_length)
35
59
  path = url.split('#')[0].split('?')[0]
36
60
  path = path["#{root}/tree/".length..-1]
61
+
62
+ return unless path
63
+
37
64
  path.length > max_length ? path[-max_length..-1] : path
38
65
  end
39
66
 
@@ -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.1.8"
5
5
  end
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.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-11-20 00:00:00.000000000 Z
13
+ date: 2020-12-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable