onebox 2.1.6 → 2.2.1

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: b6fd88926ec341ed84409e7c77dbfcce244dbf2a0c74e0a19736e81b2b693e84
4
- data.tar.gz: 18f53e5fb7b1fa4eab35ea27f87e97600e82af0eaf4fd5eed0809744bf7e53c7
3
+ metadata.gz: 90c9d1f633caf0798657ff3655a0d41cca71364ed0199bc3beea5f686df4c148
4
+ data.tar.gz: 8360d4b10bf5af91a8905e09777bd305545a8db0448b9b80301b39b7bd37b1ca
5
5
  SHA512:
6
- metadata.gz: 5a5c344336f529d53b51ac47b5b0efee1b6fb29b0b2541948d650fa1d81e11f97edfa3d1a2f8abb7915b8cf9c86e41c74b64cb40b26924e380f68d52e0015c33
7
- data.tar.gz: 9cefe31755197bbfb71ba3e741329c7bdba10fd9bb19892b237cb78b22769e0e19824119b94cb3cdd24f7bec10f4aeb91cbad3a7d40eefd84c2cbe64866908b0
6
+ metadata.gz: 232104ac79cb41e53b404e90e930d1ed229f07df11dab37d72d5267366082f8d26a9d7185dd1b51a3dfe2d1eac9d71f30fddde58203fadffb8c209bcfdfa5cd2
7
+ data.tar.gz: f25d39bc21a67607a78924abee0d31ce18137d06fc672fe820cd9d0758a155e3e5370795c924bc1f404b2be41cfd93669c7709d9616043828ee1cca588afe2b4
@@ -152,6 +152,7 @@ require_relative "engine/amazon_onebox"
152
152
  require_relative "engine/github_issue_onebox"
153
153
  require_relative "engine/github_blob_onebox"
154
154
  require_relative "engine/github_commit_onebox"
155
+ require_relative "engine/github_folder_onebox"
155
156
  require_relative "engine/github_gist_onebox"
156
157
  require_relative "engine/github_pullrequest_onebox"
157
158
  require_relative "engine/google_calendar_onebox"
@@ -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/ &&
@@ -0,0 +1,78 @@
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: url,
49
+ image: og.image,
50
+ title: Onebox::Helpers.truncate(title, 250),
51
+ path: display_path,
52
+ description: display_description,
53
+ favicon: get_favicon
54
+ }
55
+ end
56
+
57
+ def extract_path(root, max_length)
58
+ path = url.split('#')[0].split('?')[0]
59
+ path = path["#{root}/tree/".length..-1]
60
+
61
+ return unless path
62
+
63
+ path.length > max_length ? path[-max_length..-1] : path
64
+ end
65
+
66
+ def clean_description(description, title, max_length)
67
+ return unless description
68
+
69
+ desc_end = " - #{title}"
70
+ if description[-desc_end.length..-1] == desc_end
71
+ description = description[0...-desc_end.length]
72
+ end
73
+
74
+ Onebox::Helpers.truncate(description, max_length)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -7,15 +7,17 @@ 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
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,
@@ -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.6"
4
+ VERSION = "2.2.1"
5
5
  end
@@ -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='{{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.6
4
+ version: 2.2.1
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-16 00:00:00.000000000 Z
13
+ date: 2020-12-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable
@@ -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