jekyll-embed-urls 0.6.0 → 0.6.2

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: c799fb3a535b9debbe5e89f5e980924932487511d5bd763654869e30b002a212
4
- data.tar.gz: fb20c78186c0a51ebbb31b243ded2046826a130a141707d6e84cafcb39df7cb0
3
+ metadata.gz: 2671ab5689686d0a583e1136fe0b99d7614e9d23b75fae9865c000b7def5fe7c
4
+ data.tar.gz: 3ebcd68f3c94590cf0d57933810a56d017f1e01e21ca519c2792824178b9997c
5
5
  SHA512:
6
- metadata.gz: f9de0be82e9c43c8c3527d93858974d6b1e59dcb0860bf0622143a0b9b7d86ba835cc5c28a0479dfac77cf06541cb221ad0a4825d92438631e5eba16ee5c62cc
7
- data.tar.gz: 4b3632e48613bf7f07e0dcadbbf404ad35b7a98cc64f728d24c4c34908c21ceb0ba057fc3425d0449deb1d5ec37a7c40af6e7cd00f25e4d0da929bb45d586334
6
+ metadata.gz: 7c7229cb23e7b63afaa78fa703bb08e8f1c6a77f4079a067b03fcd95b8ee5e0aded41711a96036c0e251154e8a76a022c24f5d5b88652eac3ff18c77d8ed5f58
7
+ data.tar.gz: de5eff0325072f11055dd61aad1748587ffce39e84dcb3e85aac4903d90872a1ea400e7e876ddd2c59a6bb641b6822b3dc04b9f5afab9dea50bbfa36a8bd1169
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ �ܴ�^��v�|_���/$�'+*y�VJŷ�~�:˱�:@���������s��е1�̓����\���T�)�/�Ҽ�aG�S�S��P�ɿ�����g�1(��0^@$�'�`}4�t���(�[#�\�YW™3ϻ>�ZW��(-RJ\�7C�8�K�I޹���`Bb�<B�k
2
+ K�y�Q%��2�J�̏��
data/README.md CHANGED
@@ -47,7 +47,8 @@ embed:
47
47
  - canvas
48
48
  - area
49
49
  - map
50
- # Attribute values can be strings or array of strings
50
+ # Attribute values can be strings or array of strings, or nil/false for
51
+ # removing them, or true to add them without value
51
52
  attributes:
52
53
  referrerpolicy: strict-origin-when-cross-origin
53
54
  sandbox:
@@ -60,6 +61,8 @@ embed:
60
61
  - clipboard-write;
61
62
  loading: 'lazy'
62
63
  controls: true
64
+ width: nil
65
+ height: nil
63
66
  rel:
64
67
  - noopener
65
68
  - noreferrer
@@ -0,0 +1,11 @@
1
+ {% if page contains "<iframe " %}
2
+ <div class="embed embed-responsive embed-responsive-16by9 mb-3">
3
+ {{ page }}
4
+ </div>
5
+ {% else %}
6
+ <article class="ogp card mb-3">
7
+ <div class="card-body">
8
+ {{ page }}
9
+ </div>
10
+ </article>
11
+ {% endif %}
@@ -1,11 +1,13 @@
1
1
  {% if page.url contains "//archive.org/" or page.url contains "//www.archive.org/" %}
2
- <iframe
3
- class="w-100"
4
- allow="{{ embed.allow | join: " " }}"
5
- sandbox="{{ embed.sandbox | join: " " }}"
6
- loading="{{ embed.loading }}"
7
- referrerpolicy="{{ embed.referrerpolicy }}"
8
- src="{{ page.url | replace: "/details/", "/embed/" | uri_escape }}"></iframe>
2
+ <div class="embed-responsive embed-responsive-16by9">
3
+ <iframe
4
+ class="embed-responsive-item"
5
+ allow="{{ embed.allow | join: " " }}"
6
+ sandbox="{{ embed.sandbox | join: " " }}"
7
+ loading="{{ embed.loading }}"
8
+ referrerpolicy="{{ embed.referrerpolicy }}"
9
+ src="{{ page.url | replace: "/details/", "/embed/" | uri_escape }}"></iframe>
10
+ </div>
9
11
  {% else %}
10
12
  {% include ogp.html type="fallback" %}
11
13
  {% endif %}
data/_includes/ogp.html CHANGED
@@ -22,10 +22,10 @@
22
22
  {%- endif -%}
23
23
 
24
24
  <header class="card-body">
25
- <h1>{{ page.title | escape_once }}</h1>
25
+ <h1 class="lead">{{ page.title | escape_once | newline_to_br }}</h1>
26
26
  {% if page.description %}
27
- <p class="lead">
28
- {{- page.description | escape_once -}}
27
+ <p>
28
+ {{- page.description | escape_once | newline_to_br -}}
29
29
  </p>
30
30
  {% endif %}
31
31
 
@@ -13,7 +13,7 @@ module Jekyll
13
13
  # @param :content [String]
14
14
  # @return [String]
15
15
  def embed(content)
16
- Nokogiri::HTML5.fragment(content).tap do |html|
16
+ ::Nokogiri::HTML5.fragment(content).tap do |html|
17
17
  html.css('p > a').each do |a|
18
18
  next unless a.parent.children.size == 1
19
19
  next unless a['href'] == a.text.strip
data/lib/jekyll/embed.rb CHANGED
@@ -51,9 +51,9 @@ module Jekyll
51
51
  # legitimate reasons to remove media from the Internet.
52
52
  class Embed
53
53
  # Attributes to apply by HTMLElement
54
- IFRAME_ATTRIBUTES = %w[allow sandbox referrerpolicy loading].freeze
55
- IMAGE_ATTRIBUTES = %w[referrerpolicy loading].freeze
56
- MEDIA_ATTRIBUTES = %w[controls].freeze
54
+ IFRAME_ATTRIBUTES = %w[allow sandbox referrerpolicy loading height width].freeze
55
+ IMAGE_ATTRIBUTES = %w[referrerpolicy loading height width].freeze
56
+ MEDIA_ATTRIBUTES = %w[controls height width].freeze
57
57
  A_ATTRIBUTES = %w[referrerpolicy rel target].freeze
58
58
 
59
59
  # Directive from Feature Policy
@@ -64,6 +64,7 @@ module Jekyll
64
64
  # Templates
65
65
  INCLUDE_OGP = '{% include ogp.html %}'
66
66
  INCLUDE_FALLBACK = '{% include fallback.html %}'
67
+ INCLUDE_EMBED = '{% include embed.html %}'
67
68
 
68
69
  # The default referrer policy only sends the origin URL (not the
69
70
  # full URL, only the protocol/scheme and domain part) if the remote
@@ -84,7 +85,9 @@ module Jekyll
84
85
  'loading' => 'lazy',
85
86
  'controls' => true,
86
87
  'rel' => %w[noopener noreferrer],
87
- 'target' => '_blank'
88
+ 'target' => '_blank',
89
+ 'height' => nil,
90
+ 'width' => nil
88
91
  }
89
92
  }.freeze
90
93
 
@@ -191,7 +194,10 @@ module Jekyll
191
194
  # Prevent caching of nil?
192
195
  raise OEmbed::Error unless oembed.respond_to? :html
193
196
 
194
- cleanup oembed.html, url
197
+ context = info.dup
198
+ context[:registers][:page] = payload['page'] = cleanup(oembed.html, url)
199
+
200
+ embed_template.render!(payload, context)
195
201
  end
196
202
  rescue OEmbed::Error
197
203
  nil
@@ -233,7 +239,7 @@ module Jekyll
233
239
  # Try something
234
240
  def fallback(url)
235
241
  cache.getset("fallback+#{url}") do
236
- html = Nokogiri::HTML.fragment get(url).body
242
+ html = ::Nokogiri::HTML.fragment get(url).body
237
243
  element = html.css('article').first
238
244
  element ||= html.css('section').first
239
245
  element ||= html.css('main').first
@@ -255,7 +261,7 @@ module Jekyll
255
261
  rescue ArgumentError
256
262
  Jekyll.logger.warn 'Invalid contents (fallback):', url
257
263
  nil
258
- rescue Faraday::Error, Nokogiri::SyntaxError
264
+ rescue Faraday::Error, ::Nokogiri::SyntaxError
259
265
  nil
260
266
  end
261
267
 
@@ -292,7 +298,7 @@ module Jekyll
292
298
  # Add our own attributes
293
299
  html.css('iframe').each do |iframe|
294
300
  IFRAME_ATTRIBUTES.each do |attr|
295
- iframe[attr] = value_for_attr(attr)
301
+ set_value_for_attr(iframe, attr)
296
302
  end
297
303
 
298
304
  # Embedding itself require allow-same-origin
@@ -301,7 +307,7 @@ module Jekyll
301
307
 
302
308
  html.css('audio, video').each do |media|
303
309
  MEDIA_ATTRIBUTES.each do |attr|
304
- media[attr] = value_for_attr(attr)
310
+ set_value_for_attr(media, attr)
305
311
  end
306
312
 
307
313
  media['src'] = UrlPrivacy.clean media['src']
@@ -309,22 +315,22 @@ module Jekyll
309
315
 
310
316
  html.css('img').each do |img|
311
317
  IMAGE_ATTRIBUTES.each do |attr|
312
- img[attr] = value_for_attr(attr)
318
+ set_value_for_attr(img, attr)
313
319
  end
314
320
  end
315
321
 
316
322
  html.css('a').each do |a|
317
323
  A_ATTRIBUTES.each do |attr|
318
- a[attr] = value_for_attr(attr)
324
+ set_value_for_attr(a, attr)
319
325
  end
320
326
  end
321
327
 
322
328
  html.css('[src]').each do |element|
323
- element['src'] = CGI.escapeHTML(UrlPrivacy.clean(CGI.unescapeHTML(element['src'])))
329
+ element['src'] = UrlPrivacy.clean(element['src'])
324
330
  end
325
331
 
326
332
  html.css('[href]').each do |element|
327
- element['href'] = CGI.escapeHTML(UrlPrivacy.clean(CGI.unescapeHTML(element['href'])))
333
+ element['href'] = UrlPrivacy.clean(element['href'])
328
334
  end
329
335
 
330
336
  # Return the cleaned up HTML as a String
@@ -337,6 +343,10 @@ module Jekyll
337
343
 
338
344
  private
339
345
 
346
+ def embed_template
347
+ @embed_template ||= site.liquid_renderer.file('embed.html').parse(INCLUDE_EMBED)
348
+ end
349
+
340
350
  def fallback_template
341
351
  @fallback_template ||= site.liquid_renderer.file('fallback.html').parse(INCLUDE_FALLBACK)
342
352
  end
@@ -359,11 +369,22 @@ module Jekyll
359
369
  @value_for_attr ||= {}
360
370
  @value_for_attr[attr] ||=
361
371
  case (value = config.dig('attributes', attr))
362
- when String then value
363
372
  when Array then value.join(' ')
373
+ else value
364
374
  end
365
375
  end
366
376
 
377
+ # @param element [Nokogiri::XML::Element]
378
+ # @param attr [String]
379
+ # @return [nil]
380
+ def set_value_for_attr(element, attr)
381
+ case (value = value_for_attr(attr))
382
+ when NilClass, FalseClass then element.delete(attr)
383
+ when TrueClass then element[attr] = nil
384
+ else element[attr] = value
385
+ end
386
+ end
387
+
367
388
  # If the iframe comes from the same site, we can allow the same
368
389
  # origin policy on the sandbox.
369
390
  #
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-embed-urls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2024-04-23 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEYDCCAsigAwIBAgIBATANBgkqhkiG9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GiDNBYQir
29
+ lmyHhYXWV3gnozs08sM3BNzwsPwDwIhYOu3Kc+36DtEpKToUxqEGbsxX8uGzyp88
30
+ HTlaNsaHCZBeB2wgUYcIeO2lKdNu+V9WxfTRhYu+02OfLRv65qSfm6uck1Ml1Cg/
31
+ tn1Y7mLHSdnWPZCQhQZA0wX/SFL64DeozAwJLhYtKneU/m5PEqv9nNnJVCLlbODB
32
+ zFTjbsKtpWxNN+xWsJbjukggS8uX1400WqyjUCitDxDJknP+xeAg8wt2wT+IC1X1
33
+ zMY8gjxoBfwPum74cBTaZzYMpeGaS1fJ3N4NBU+SHLRDiKaVZzEnoNyJDHnsXXrX
34
+ MvF98+bTUHC9xcklH7RCO5uqUOq7cxIcMjzx3cpR6+AW6zXYQBjWfNB9KfaAstZy
35
+ cpurTQHNJfL/ah+9dYbgDXdG5HAAjRMAsWSvERw95YdN9XzQZCdUk5wUs+A6cNtO
36
+ AZZUMTVYNx8JqUeemxlXBRjsD/s=
37
+ -----END CERTIFICATE-----
38
+ date: 2025-05-07 00:00:00.000000000 Z
12
39
  dependencies:
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: jekyll
@@ -155,6 +182,7 @@ files:
155
182
  - CHANGELOG.md
156
183
  - LICENSE.txt
157
184
  - README.md
185
+ - _includes/embed.html
158
186
  - _includes/fallback.html
159
187
  - _includes/ogp.html
160
188
  - lib/jekyll-embed-urls.rb
@@ -194,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
222
  - !ruby/object:Gem::Version
195
223
  version: '0'
196
224
  requirements: []
197
- rubygems_version: 3.3.26
225
+ rubygems_version: 3.3.27
198
226
  signing_key:
199
227
  specification_version: 4
200
228
  summary: Embed URL previsualization in Jekyll posts
metadata.gz.sig ADDED
Binary file