jekyll-embed-urls 0.6.0 → 0.6.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: c799fb3a535b9debbe5e89f5e980924932487511d5bd763654869e30b002a212
4
- data.tar.gz: fb20c78186c0a51ebbb31b243ded2046826a130a141707d6e84cafcb39df7cb0
3
+ metadata.gz: f36b8e03926204a17b34959a0216a6e2fa08a02a57f46826be1daf893865ede0
4
+ data.tar.gz: 92581158508c23138f1676284762f8df046c601f5b2afff205fbc43c00e691aa
5
5
  SHA512:
6
- metadata.gz: f9de0be82e9c43c8c3527d93858974d6b1e59dcb0860bf0622143a0b9b7d86ba835cc5c28a0479dfac77cf06541cb221ad0a4825d92438631e5eba16ee5c62cc
7
- data.tar.gz: 4b3632e48613bf7f07e0dcadbbf404ad35b7a98cc64f728d24c4c34908c21ceb0ba057fc3425d0449deb1d5ec37a7c40af6e7cd00f25e4d0da929bb45d586334
6
+ metadata.gz: 596771a5208ad6f7abffdda7f4788ec26cd7f1b52bd93988f38bfff7aa64541a109a1ad1e4e814f987f87278bf9d32b00fb348b9a127fc90a0858b110f94bd12
7
+ data.tar.gz: ed39244b6769b3044e6b00a16666264d22eabea3a50cd97722122a5e18a5534ecbbfeef12267902a76000abc7204f8c2417ee4a52131aee6becf82e10a1d057b
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
 
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
@@ -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
  #
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
@@ -155,6 +155,7 @@ files:
155
155
  - CHANGELOG.md
156
156
  - LICENSE.txt
157
157
  - README.md
158
+ - _includes/embed.html
158
159
  - _includes/fallback.html
159
160
  - _includes/ogp.html
160
161
  - lib/jekyll-embed-urls.rb