onebox 2.2.12 → 2.2.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -4
  3. data/lib/onebox/engine.rb +1 -1
  4. data/lib/onebox/engine/allowlisted_generic_onebox.rb +11 -9
  5. data/lib/onebox/engine/amazon_onebox.rb +3 -1
  6. data/lib/onebox/engine/asciinema_onebox.rb +0 -1
  7. data/lib/onebox/engine/audioboom_onebox.rb +5 -2
  8. data/lib/onebox/engine/bandcamp_onebox.rb +8 -8
  9. data/lib/onebox/engine/cloudapp_onebox.rb +12 -12
  10. data/lib/onebox/engine/coub_onebox.rb +0 -1
  11. data/lib/onebox/engine/facebook_media_onebox.rb +8 -7
  12. data/lib/onebox/engine/five_hundred_px_onebox.rb +0 -1
  13. data/lib/onebox/engine/flickr_onebox.rb +14 -15
  14. data/lib/onebox/engine/giphy_onebox.rb +0 -1
  15. data/lib/onebox/engine/github_blob_onebox.rb +4 -0
  16. data/lib/onebox/engine/github_commit_onebox.rb +2 -3
  17. data/lib/onebox/engine/github_gist_onebox.rb +1 -2
  18. data/lib/onebox/engine/github_issue_onebox.rb +16 -18
  19. data/lib/onebox/engine/github_pullrequest_onebox.rb +7 -4
  20. data/lib/onebox/engine/gitlab_blob_onebox.rb +4 -0
  21. data/lib/onebox/engine/google_calendar_onebox.rb +1 -1
  22. data/lib/onebox/engine/google_docs_onebox.rb +7 -7
  23. data/lib/onebox/engine/google_drive_onebox.rb +7 -7
  24. data/lib/onebox/engine/google_maps_onebox.rb +0 -2
  25. data/lib/onebox/engine/google_photos_onebox.rb +14 -14
  26. data/lib/onebox/engine/google_play_app_onebox.rb +3 -7
  27. data/lib/onebox/engine/instagram_onebox.rb +2 -2
  28. data/lib/onebox/engine/kaltura_onebox.rb +8 -6
  29. data/lib/onebox/engine/opengraph_image.rb +0 -1
  30. data/lib/onebox/engine/pubmed_onebox.rb +3 -2
  31. data/lib/onebox/engine/replit_onebox.rb +0 -1
  32. data/lib/onebox/engine/sketchfab_onebox.rb +8 -8
  33. data/lib/onebox/engine/slides_onebox.rb +10 -10
  34. data/lib/onebox/engine/soundcloud_onebox.rb +0 -1
  35. data/lib/onebox/engine/stack_exchange_onebox.rb +2 -1
  36. data/lib/onebox/engine/standard_embed.rb +2 -2
  37. data/lib/onebox/engine/steam_store_onebox.rb +6 -5
  38. data/lib/onebox/engine/trello_onebox.rb +2 -2
  39. data/lib/onebox/engine/twitch_clips_onebox.rb +1 -3
  40. data/lib/onebox/engine/twitch_stream_onebox.rb +1 -2
  41. data/lib/onebox/engine/twitch_video_onebox.rb +0 -2
  42. data/lib/onebox/engine/typeform_onebox.rb +7 -6
  43. data/lib/onebox/engine/vimeo_onebox.rb +9 -7
  44. data/lib/onebox/engine/wikimedia_onebox.rb +1 -2
  45. data/lib/onebox/engine/wikipedia_onebox.rb +12 -8
  46. data/lib/onebox/engine/youku_onebox.rb +7 -7
  47. data/lib/onebox/engine/youtube_onebox.rb +14 -13
  48. data/lib/onebox/file_type_finder.rb +0 -1
  49. data/lib/onebox/helpers.rb +2 -2
  50. data/lib/onebox/mixins/git_blob_onebox.rb +5 -3
  51. data/lib/onebox/mixins/github_body.rb +30 -0
  52. data/lib/onebox/mixins/twitch_onebox.rb +0 -1
  53. data/lib/onebox/preview.rb +1 -2
  54. data/lib/onebox/version.rb +1 -1
  55. data/templates/github/github_body.mustache +3 -0
  56. data/templates/githubissue.mustache +7 -9
  57. data/templates/githubpullrequest.mustache +4 -16
  58. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdbe1e67e709c8a2c8179a7118f4b51447a15a1bf1b56619fc601d3a9486123e
4
- data.tar.gz: 8a72a7fc2152789c4103de330b7dcd69ec9a9c487fdc499a6068bdd0840e2e26
3
+ metadata.gz: ee0229502d76efea853fff81a0e756e33867b7034219bb56805dcf891ab42207
4
+ data.tar.gz: 9e6f581f0dd784f0edb841c05f4faa785bae4cfaf4ac2c482050034ead36b912
5
5
  SHA512:
6
- metadata.gz: 3fe9a20e93b0aea3a3a7362bb5e9f026ddb63ab0c7edb64f5b7a1d9831fa76d001314ea0fdf07c92daefe95fc096e8068d28e3e6f5c7860689e5545646031084
7
- data.tar.gz: 4e2e19424dab311c7a56feec82486333520f72575f95acccd1a11b8419616d2ea895e02472542d6bcdce7c5d6fbf72f887eab3941f67dd546762349bec3b66a9
6
+ metadata.gz: 7139dd42d40ebf30b4228c41018db4408fd53c196838c0b8d94afae27ba30d1ba258fc57fbea7ff432619f473a2e22c86b62251c094591f9a9ec90693b768655
7
+ data.tar.gz: 69d506c95f5fbf5526967195ce5f9c1224c1af71f72f0477063e4a8a0e59b8ab4300270cc28aae2cfc74f5e41187b3e3aed11b1656e83c0e766293eb932ca84a
data/.rspec CHANGED
@@ -1,5 +1 @@
1
1
  --color
2
- --format documentation
3
- --fail-fast
4
- --backtrace
5
-
data/lib/onebox/engine.rb CHANGED
@@ -136,7 +136,7 @@ module Onebox
136
136
  end
137
137
 
138
138
  def always_https?
139
- @https
139
+ defined?(@https) ? @https : false
140
140
  end
141
141
  end
142
142
  end
@@ -374,15 +374,17 @@ module Onebox
374
374
  escaped_image_src = ::Onebox::Helpers.normalize_url_for_output(data[:image])
375
375
 
376
376
  <<-HTML
377
- <video title='#{data[:title]}'
378
- width='#{data[:video_width]}'
379
- height='#{data[:video_height]}'
380
- style='max-width:100%'
381
- poster='#{escaped_image_src}'
382
- controls=''>
383
- <source src='#{escaped_video_src}'>
384
- </video>
385
- HTML
377
+ <video
378
+ title='#{data[:title]}'
379
+ width='#{data[:video_width]}'
380
+ height='#{data[:video_height]}'
381
+ style='max-width:100%'
382
+ poster='#{escaped_image_src}'
383
+ controls=''
384
+ >
385
+ <source src='#{escaped_video_src}'>
386
+ </video>
387
+ HTML
386
388
  end
387
389
 
388
390
  def embedded_html
@@ -14,6 +14,8 @@ module Onebox
14
14
  matches_regexp(/^https?:\/\/(?:www\.)?(?:smile\.)?(amazon|amzn)\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br|com\.mx|nl|pl|sa|sg|se|com\.tr|ae)\//)
15
15
 
16
16
  def url
17
+ @raw ||= nil
18
+
17
19
  # If possible, fetch the cached HTML body immediately so we can
18
20
  # try to grab the canonical URL from that document,
19
21
  # rather than guess at the best URL structure to use
@@ -36,7 +38,7 @@ module Onebox
36
38
  end
37
39
 
38
40
  def tld
39
- @tld || @@matcher.match(@url)["tld"]
41
+ @tld ||= @@matcher.match(@url)["tld"]
40
42
  end
41
43
 
42
44
  def http_params
@@ -7,7 +7,6 @@ module Onebox
7
7
  include StandardEmbed
8
8
 
9
9
  always_https
10
-
11
10
  matches_regexp(/^https?:\/\/asciinema\.org\/a\/[\p{Alnum}_\-]+$/)
12
11
 
13
12
  def to_html
@@ -13,14 +13,17 @@ module Onebox
13
13
  oembed = get_oembed
14
14
 
15
15
  <<-HTML
16
- <img src="#{oembed.thumbnail_url}" style="max-width: #{oembed.width}px; max-height: #{oembed.height}px;" #{oembed.title_attr}>
16
+ <img
17
+ src="#{oembed.thumbnail_url}"
18
+ style="max-width: #{oembed.width}px; max-height: #{oembed.height}px;"
19
+ #{oembed.title_attr}
20
+ >
17
21
  HTML
18
22
  end
19
23
 
20
24
  def to_html
21
25
  get_oembed.html
22
26
  end
23
-
24
27
  end
25
28
  end
26
29
  end
@@ -20,16 +20,16 @@ module Onebox
20
20
  escaped_src = og.video_secure_url || og.video
21
21
 
22
22
  <<-HTML
23
- <iframe src="#{escaped_src}"
24
- width="#{og.video_width}"
25
- height="#{og.video_height}"
26
- scrolling="no"
27
- frameborder="0"
28
- allowfullscreen>
29
- </iframe>
23
+ <iframe
24
+ src="#{escaped_src}"
25
+ width="#{og.video_width}"
26
+ height="#{og.video_height}"
27
+ scrolling="no"
28
+ frameborder="0"
29
+ allowfullscreen
30
+ ></iframe>
30
31
  HTML
31
32
  end
32
-
33
33
  end
34
34
  end
35
35
  end
@@ -25,28 +25,28 @@ module Onebox
25
25
 
26
26
  def link_html(og)
27
27
  <<-HTML
28
- <a href='#{og.url}' target='_blank' rel='noopener'>
29
- #{og.title}
30
- </a>
31
- HTML
28
+ <a href='#{og.url}' target='_blank' rel='noopener'>
29
+ #{og.title}
30
+ </a>
31
+ HTML
32
32
  end
33
33
 
34
34
  def video_html(og)
35
35
  direct_src = ::Onebox::Helpers.normalize_url_for_output("#{og.get(:url)}/#{og.title}")
36
36
 
37
37
  <<-HTML
38
- <video width='480' height='360' #{og.title_attr} controls loop>
39
- <source src='#{direct_src}' type='video/mp4'>
40
- </video>
41
- HTML
38
+ <video width='480' height='360' #{og.title_attr} controls loop>
39
+ <source src='#{direct_src}' type='video/mp4'>
40
+ </video>
41
+ HTML
42
42
  end
43
43
 
44
44
  def image_html(og)
45
45
  <<-HTML
46
- <a href='#{og.url}' target='_blank' class='onebox' rel='noopener'>
47
- <img src='#{og.image}' #{og.title_attr} alt='CloudApp' width='480'>
48
- </a>
49
- HTML
46
+ <a href='#{og.url}' target='_blank' class='onebox' rel='noopener'>
47
+ <img src='#{og.image}' #{og.title_attr} alt='CloudApp' width='480'>
48
+ </a>
49
+ HTML
50
50
  end
51
51
  end
52
52
  end
@@ -17,7 +17,6 @@ module Onebox
17
17
  def to_html
18
18
  get_oembed.html
19
19
  end
20
-
21
20
  end
22
21
  end
23
22
  end
@@ -14,13 +14,14 @@ module Onebox
14
14
  metadata = get_twitter
15
15
  if metadata.present? && metadata[:card] == "player" && metadata[:player].present?
16
16
  <<-HTML
17
- <iframe src="#{metadata[:player]}"
18
- width="#{metadata[:player_width]}"
19
- height="#{metadata[:player_height]}"
20
- scrolling="no"
21
- frameborder="0"
22
- allowfullscreen>
23
- </iframe>
17
+ <iframe
18
+ src="#{metadata[:player]}"
19
+ width="#{metadata[:player_width]}"
20
+ height="#{metadata[:player_height]}"
21
+ scrolling="no"
22
+ frameborder="0"
23
+ allowfullscreen
24
+ ></iframe>
24
25
  HTML
25
26
  else
26
27
  html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html
@@ -13,7 +13,6 @@ module Onebox
13
13
  og = get_opengraph
14
14
  "<img src='#{og.image}' width='#{og.image_width}' height='#{og.image_height}' class='onebox' #{og.title_attr}>"
15
15
  end
16
-
17
16
  end
18
17
  end
19
18
  end
@@ -25,29 +25,28 @@ module Onebox
25
25
  album_title = "[Album] #{og.title}"
26
26
 
27
27
  <<-HTML
28
- <div class='onebox flickr-album'>
29
- <a href='#{escaped_url}' target='_blank' rel='noopener'>
30
- <span class='outer-box' style='max-width:#{og.image_width}px'>
31
- <span class='inner-box'>
32
- <span class='album-title'>#{album_title}</span>
33
- </span>
28
+ <div class='onebox flickr-album'>
29
+ <a href='#{escaped_url}' target='_blank' rel='noopener'>
30
+ <span class='outer-box' style='max-width:#{og.image_width}px'>
31
+ <span class='inner-box'>
32
+ <span class='album-title'>#{album_title}</span>
34
33
  </span>
35
- <img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
36
- </a>
37
- </div>
38
- HTML
34
+ </span>
35
+ <img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
36
+ </a>
37
+ </div>
38
+ HTML
39
39
  end
40
40
 
41
41
  def image_html(og)
42
42
  escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
43
43
 
44
44
  <<-HTML
45
- <a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
46
- <img src='#{og.get_secure_image}' #{og.title_attr} alt='Imgur' height='#{og.image_height}' width='#{og.image_width}'>
47
- </a>
48
- HTML
45
+ <a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
46
+ <img src='#{og.get_secure_image}' #{og.title_attr} alt='Imgur' height='#{og.image_height}' width='#{og.image_width}'>
47
+ </a>
48
+ HTML
49
49
  end
50
-
51
50
  end
52
51
  end
53
52
  end
@@ -18,7 +18,6 @@ module Onebox
18
18
  </a>
19
19
  HTML
20
20
  end
21
-
22
21
  end
23
22
  end
24
23
  end
@@ -8,17 +8,21 @@ module Onebox
8
8
  def self.git_regexp
9
9
  /^https?:\/\/(www\.)?github\.com.*\/blob\//
10
10
  end
11
+
11
12
  def self.onebox_name
12
13
  "githubblob"
13
14
  end
14
15
 
15
16
  include Onebox::Mixins::GitBlobOnebox
17
+
16
18
  def raw_regexp
17
19
  /github\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
18
20
  end
21
+
19
22
  def raw_template(m)
20
23
  "https://raw.githubusercontent.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
21
24
  end
25
+
22
26
  def title
23
27
  Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/github\.com\//, ''))
24
28
  end
@@ -17,11 +17,10 @@ module Onebox
17
17
  private
18
18
 
19
19
  def match
20
- return @match if @match
20
+ return @match if defined?(@match)
21
21
 
22
22
  @match = @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/commit/(?<sha>[^/]+)})
23
-
24
- @match = @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<pr>[^/]+)/commit/(?<sha>[^/]+)}) if @match.nil?
23
+ @match ||= @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<pr>[^/]+)/commit/(?<sha>[^/]+)})
25
24
 
26
25
  @match
27
26
  end
@@ -9,7 +9,7 @@ module Onebox
9
9
 
10
10
  MAX_FILES = 3
11
11
 
12
- matches_regexp Regexp.new("^http(?:s)?://gist\\.(?:(?:\\w)+\\.)?(github)\\.com(?:/)?")
12
+ matches_regexp(/^http(?:s)?:\/\/gist\.(?:(?:\w)+\.)?(github)\.com(?:\/)?/)
13
13
  always_https
14
14
 
15
15
  def url
@@ -76,7 +76,6 @@ module Onebox
76
76
  @lines ||= @json["content"].split("\n")
77
77
  end
78
78
  end
79
-
80
79
  end
81
80
  end
82
81
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../mixins/github_body'
4
+
3
5
  module Onebox
4
6
  module Engine
5
7
  class GithubIssueOnebox
@@ -7,7 +9,9 @@ module Onebox
7
9
  include Engine
8
10
  include LayoutSupport
9
11
  include JSON
10
- matches_regexp Regexp.new("^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?github\.com\/(?<org>.+)\/(?<repo>.+)\/issues\/([[:digit:]]+)")
12
+ include Onebox::Mixins::GithubBody
13
+
14
+ matches_regexp(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?github\.com\/(?<org>.+)\/(?<repo>.+)\/issues\/([[:digit:]]+)/)
11
15
  always_https
12
16
 
13
17
  def url
@@ -22,32 +26,26 @@ module Onebox
22
26
  end
23
27
 
24
28
  def data
25
- @raw ||= ::MultiJson.load(URI.open(url, "Accept" => "application/vnd.github.v3.text+json", read_timeout: timeout)) #custom Accept header so we can get body as text.
26
- body_text = @raw["body_text"]
27
-
28
- content_words = body_text.gsub("\n\n", "\n").gsub("\n", "<br>").split(" ") #one pass of removing double newline, then we change \n to <br> and later on we revert it back to \n this is a workaround to avoid losing newlines after we join it back.
29
- max_words = 20
30
- short_content = content_words[0..max_words].join(" ")
31
- short_content += "..." if content_words.length > max_words
32
-
33
- created_at = Time.parse(@raw['created_at'])
34
- closed_at = Time.parse(@raw['closed_at']) if @raw['closed_at']
35
-
29
+ created_at = Time.parse(raw['created_at'])
30
+ closed_at = Time.parse(raw['closed_at']) if raw['closed_at']
31
+ body, excerpt = compute_body(raw['body'])
36
32
  ulink = URI(link)
33
+
37
34
  {
38
35
  link: @url,
39
- title: @raw["title"],
40
- content: short_content.gsub("<br>", "\n"),
41
- labels: @raw["labels"],
42
- user: @raw['user'],
36
+ title: raw["title"],
37
+ body: body,
38
+ excerpt: excerpt,
39
+ labels: raw["labels"],
40
+ user: raw['user'],
43
41
  created_at: created_at.strftime("%I:%M%p - %d %b %y %Z"),
44
42
  created_at_date: created_at.strftime("%F"),
45
43
  created_at_time: created_at.strftime("%T"),
46
44
  closed_at: closed_at&.strftime("%I:%M%p - %d %b %y %Z"),
47
45
  closed_at_date: closed_at&.strftime("%F"),
48
46
  closed_at_time: closed_at&.strftime("%T"),
49
- closed_by: @raw['closed_by'],
50
- avatar: "https://avatars1.githubusercontent.com/u/#{@raw['user']['id']}?v=2&s=96",
47
+ closed_by: raw['closed_by'],
48
+ avatar: "https://avatars1.githubusercontent.com/u/#{raw['user']['id']}?v=2&s=96",
51
49
  domain: "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}",
52
50
  }
53
51
  end
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../mixins/github_body'
4
+
3
5
  module Onebox
4
6
  module Engine
5
7
  class GithubPullRequestOnebox
6
8
  include Engine
7
9
  include LayoutSupport
8
10
  include JSON
11
+ include Onebox::Mixins::GithubBody
12
+
13
+ GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/
9
14
 
10
- matches_regexp Regexp.new("^https?://(?:www\\.)?(?:(?:\\w)+\\.)?(github)\\.com(?:/)?(?:.)*/pull/")
15
+ matches_regexp(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com(?:\/)?(?:.)*\/pull/)
11
16
  always_https
12
17
 
13
18
  def url
@@ -20,7 +25,6 @@ module Onebox
20
25
  @match ||= @url.match(%r{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<number>[^/]+)})
21
26
  end
22
27
 
23
- GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/
24
28
  def data
25
29
  result = raw.clone
26
30
  result['link'] = link
@@ -33,8 +37,7 @@ module Onebox
33
37
  ulink = URI(link)
34
38
  result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
35
39
 
36
- body = (result['body'] || '').gsub(GITHUB_COMMENT_REGEX, '')
37
- result['body'] = body.present? ? body : nil
40
+ result['body'], result['excerpt'] = compute_body(result['body'])
38
41
 
39
42
  result
40
43
  end
@@ -8,17 +8,21 @@ module Onebox
8
8
  def self.git_regexp
9
9
  /^https?:\/\/(www\.)?gitlab\.com.*\/blob\//
10
10
  end
11
+
11
12
  def self.onebox_name
12
13
  "gitlabblob"
13
14
  end
14
15
 
15
16
  include Onebox::Mixins::GitBlobOnebox
17
+
16
18
  def raw_regexp
17
19
  /gitlab\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
18
20
  end
21
+
19
22
  def raw_template(m)
20
23
  "https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
21
24
  end
25
+
22
26
  def title
23
27
  Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
24
28
  end