jekyll-embed-urls 0.5.7 → 0.5.9

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: '009ec95cb733855d621b7b063e4922c79873296fdebd99f16ad6f2856854a7af'
4
- data.tar.gz: e56ca532db963a099a4c4c6950c4382ca25d83c5102703b8bf2d66fd98d8f2a9
3
+ metadata.gz: e5ec0df3dfa0876c1bdd5288ee70e5c7466dddb1d4f592339ee8855ee8b0d680
4
+ data.tar.gz: 12936601d35523b31d85233c53c9663834012af1631f07155a550d89e9e99af4
5
5
  SHA512:
6
- metadata.gz: d60e0cfb3395976201a2b9b4174aaf1b888ef88fede4c802302002787471a0d8268c89d8d1cb447fa24bcebee7ac5f4ce83865b5770e0fe5ca38cd93ebb7e8e4
7
- data.tar.gz: 4310e1aa4409b2724e8dfc9b68ecc96e4eabe83709a19cb7e5d3745a895b9e7bb32af78dece340f6c4e37807813582cdb07517253a40f739c7206db03db606f3
6
+ metadata.gz: 81cf85b599fbf906e97cdf613a72491b00201c3ee5146d5dc79b9905c653e0129ccfde210ba64575c9e354df8e9f4c52345e88771e6ef4b58d4255a01a140878
7
+ data.tar.gz: ccefa67e84ec9d2f24a3b1cba04dfb2cc285726b48528a486f468b50e335bd6902d07f3b2be016c4527a2f9e5d2cb69ebb9f60ff988974911e4da8989f60133a
@@ -1,27 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi'
3
+ require 'nokogiri'
4
4
 
5
5
  module Jekyll
6
6
  class Embed
7
7
  class Content
8
- URL_RE = %r{(<p[^>]*>[\s\n]*(<a[^>]*>)?[\s\n]*(https?://[^<\s\n]+)[\s\n]*(</a>)?[\s\n]*</p>)}m.freeze
9
-
10
8
  class << self
11
9
  # Find URLs on paragraphs. We do it after rendering because
12
10
  # sometimes we use HTML instead of pure Markdown and this way we
13
11
  # catch both.
14
- def embed!(content)
15
- content.gsub!(URL_RE) do |match|
16
- url = CGI.unescapeHTML(Regexp.last_match(3))
17
- embed = Jekyll::Embed.embed url
12
+ #
13
+ # @param :content [String]
14
+ # @return [String]
15
+ def embed(content)
16
+ Nokogiri::HTML5.fragment(content).tap do |html|
17
+ html.css('p > a:first-of-type').each do |a|
18
+ next if a.parent.children.last == a
19
+
20
+ url = a['href']
21
+ embed = Jekyll::Embed.embed url
22
+
23
+ next if url == embed
18
24
 
19
- if embed == url
20
- match
21
- else
22
- embed
25
+ a.parent.replace embed
23
26
  end
24
- end
27
+ end.to_s
25
28
  end
26
29
  end
27
30
  end
@@ -29,5 +32,5 @@ module Jekyll
29
32
  end
30
33
 
31
34
  Jekyll::Hooks.register :posts, :post_convert do |post|
32
- Jekyll::Embed::Content.embed! post.content
35
+ post.content = Jekyll::Embed::Content.embed post.content
33
36
  end
@@ -6,7 +6,7 @@ module OEmbed
6
6
  module ProviderDecorator
7
7
  def self.included(base)
8
8
  base.class_eval do
9
- def http_get(url, _)
9
+ private def http_get(url, _)
10
10
  Jekyll::Embed.get(url.to_s).body
11
11
  rescue Faraday::Error
12
12
  raise OEmbed::UnknownResponse
@@ -17,3 +17,4 @@ module OEmbed
17
17
  end
18
18
 
19
19
  OEmbed::Provider.include OEmbed::ProviderDecorator
20
+ OEmbed::ProviderDiscovery.singleton_class.include OEmbed::ProviderDecorator
data/lib/jekyll/embed.rb CHANGED
@@ -265,6 +265,10 @@ module Jekyll
265
265
  # @return [Faraday::Connection]
266
266
  def http_client
267
267
  @http_client ||= Faraday.new do |builder|
268
+ builder.options.timeout = 4
269
+ builder.options.open_timeout = 1
270
+ builder.options.read_timeout = 1
271
+ builder.options.write_timeout = 1
268
272
  builder.use FaradayMiddleware::FollowRedirects
269
273
  builder.use :http_cache, shared_cache: false, store: cache, serializer: Marshal
270
274
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-embed-urls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  requirements: []
197
- rubygems_version: 3.1.6
197
+ rubygems_version: 3.3.26
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Embed URL previsualization in Jekyll posts