jekyll-embed-urls 0.5.4 → 0.5.6

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: f770c704facb923c9c12f83dd89702e44f593335921dbe2999a00f7fefcfea97
4
- data.tar.gz: bca6ebe424d64966320dd74a34d2602fc84b0c86605be53bb1f5aeb7f9d5831c
3
+ metadata.gz: 0e6e72a30b43d661e9c852d548f48ba8f600cbbde41e6873489cf9ceb3d4435c
4
+ data.tar.gz: dd437ba4bbfa32d8e9c26792a3547672ae4197d8b23029b538d3a1ca814e64b7
5
5
  SHA512:
6
- metadata.gz: 810d778e17e4a84df3bda8f8a4df90fa3deaa528c001066d28f8af92d5570d86e30b77e77de663d7f730adc44f45276ec04a8a0dc88c9e0e1d0aaac6033532a8
7
- data.tar.gz: 80f9a13ff8846bbb515e9e8f9b3f36491c1d12043d8d2a5857463252560ddb9b6b7331f24fa219992090e20ead4cb68822b839a989dba5dd0deb4614b92dec1e
6
+ metadata.gz: 9c6cb5356446f930287dd1feca9ac024db143a0f3bf531dc19f94e6e7b4a2602125a2b20bafb1029da46ad15c4cdfcbb4c2e783967f6bba16e1b21310c496557
7
+ data.tar.gz: b98314a98b042a9c7cf1f9cfbeacce6662d11b6c5ec8d6d85e0d96ea3f2bc32d0e0bcea8cf3fd387b7872fcbeb0555d2873ff242dc84f8e503e40a2374f23140
@@ -6,8 +6,8 @@
6
6
  <img src="{{ page.image | uri_escape }}" class="img-fluid" />
7
7
  {%- endif -%}
8
8
 
9
- <h1>{{ page.title }}</h1>
10
- <p class="lead">{{ page.description }}</p>
9
+ <h1>{{ page.title | escape_once }}</h1>
10
+ <p class="lead">{{ page.description | escape_once }}</p>
11
11
  <p>
12
12
  <small>
13
13
  <a href="{{ page.url | uri_escape }}">{{ page.url }}</a>
data/_includes/ogp.html CHANGED
@@ -9,8 +9,8 @@
9
9
  <audio class="img-fluid" src="{{ page.audio | uri_escape }}"/>
10
10
  {%- endif -%}
11
11
 
12
- <h1>{{ page.title }}</h1>
13
- <p class="lead">{{ page.description }}</p>
12
+ <h1>{{ page.title | escape_once }}</h1>
13
+ <p class="lead">{{ page.description | escape_once }}</p>
14
14
  <p>
15
15
  <small>
16
16
  <a href="{{ page.url | uri_escape }}">{{ page.url }}</a>
@@ -12,8 +12,15 @@ module Jekyll
12
12
  # sometimes we use HTML instead of pure Markdown and this way we
13
13
  # catch both.
14
14
  def embed!(content)
15
- content.gsub!(URL_RE) do |_|
16
- Jekyll::Embed.embed CGI.unescapeHTML($3)
15
+ content.gsub!(URL_RE) do |match|
16
+ url = CGI.unescapeHTML($3)
17
+ embed = Jekyll::Embed.embed url
18
+
19
+ if embed == url
20
+ match
21
+ else
22
+ embed
23
+ end
17
24
  end
18
25
  end
19
26
  end
data/lib/jekyll/embed.rb CHANGED
@@ -160,7 +160,7 @@ module Jekyll
160
160
  # TODO: Use Addressable
161
161
  URI.parse url
162
162
 
163
- oembed(url) || ogp(url) || fallback(url)
163
+ oembed(url) || ogp(url) || fallback(url) || url
164
164
  rescue URI::Error
165
165
  Jekyll.logger.warn "#{url.inspect} is not a valid URL"
166
166
 
@@ -197,17 +197,23 @@ module Jekyll
197
197
  def ogp(url)
198
198
  cache.getset("ogp+#{url}") do
199
199
  ogp = OGP::OpenGraph.new get(url).body
200
- context = info.dup
201
- context[:registers][:page] = payload['page'] = {
200
+ page = {
202
201
  locale: ogp.locales.first,
203
- image: ogp.images.first&.url,
204
202
  title: ogp.title,
205
203
  url: ogp.url,
206
- audio: ogp.audios.first&.url,
207
- video: ogp.videos.first&.url,
208
204
  description: ogp.description,
209
- type: ogp.type
210
- }
205
+ type: ogp.type,
206
+ data: ogp.data
207
+ }.transform_keys(&:to_s)
208
+
209
+ %w[image video audio].each do |attr|
210
+ page[attr] = ogp.public_send(:"#{attr}s").find do |a|
211
+ http? i.url
212
+ end
213
+ end
214
+
215
+ context = info.dup
216
+ context[:registers][:page] = payload['page'] = page
211
217
 
212
218
  cleanup ogp_template.render!(payload, context), url
213
219
  end
@@ -364,6 +370,16 @@ module Jekyll
364
370
  def payload
365
371
  @payload ||= site.site_payload
366
372
  end
373
+
374
+ # Discover if a string is a valid HTTP URL
375
+ #
376
+ # @param :url [String]
377
+ # @return [Boolean]
378
+ def http?(url)
379
+ url.start_with?('http') && URI.parse(url).is_a?(URI::HTTP)
380
+ rescue URI::Error
381
+ false
382
+ end
367
383
  end
368
384
  end
369
385
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-embed-urls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - f