jekyll-embed-urls 0.5.15 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/_includes/embed.html +11 -0
- data/_includes/fallback.html +10 -14
- data/_includes/ogp.html +33 -11
- data/lib/jekyll/embed/content.rb +5 -8
- data/lib/jekyll/embed.rb +37 -16
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f36b8e03926204a17b34959a0216a6e2fa08a02a57f46826be1daf893865ede0
|
4
|
+
data.tar.gz: 92581158508c23138f1676284762f8df046c601f5b2afff205fbc43c00e691aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/_includes/fallback.html
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
{% if page.url contains "//archive.org/" or page.url contains "//www.archive.org/" %}
|
2
|
-
<
|
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>
|
3
11
|
{% else %}
|
4
|
-
|
5
|
-
{%- if page.image -%}
|
6
|
-
<img src="{{ page.image | uri_escape }}" class="img-fluid" />
|
7
|
-
{%- endif -%}
|
8
|
-
|
9
|
-
<h1>{{ page.title | escape_once }}</h1>
|
10
|
-
<p class="lead">{{ page.description | escape_once }}</p>
|
11
|
-
<p>
|
12
|
-
<small>
|
13
|
-
<a href="{{ page.url | uri_escape }}">{{ page.url }}</a>
|
14
|
-
</small>
|
15
|
-
</p>
|
16
|
-
</article>
|
12
|
+
{% include ogp.html type="fallback" %}
|
17
13
|
{% endif %}
|
data/_includes/ogp.html
CHANGED
@@ -1,19 +1,41 @@
|
|
1
|
-
<article class="ogp" lang="{{ page.locale }}">
|
1
|
+
<article class="{{ include.type | default: "ogp" }} card mb-3" lang="{{ page.locale }}">
|
2
2
|
{%- if page.video -%}
|
3
|
-
<video
|
3
|
+
<video
|
4
|
+
{% if embed.controls %}controls{% endif %}
|
5
|
+
poster="{{ page.image | uri_escape }}"
|
6
|
+
preload="none"
|
7
|
+
class="img-fluid"
|
8
|
+
src="{{ page.video | uri_escape }}"/>
|
4
9
|
{%- elsif page.image -%}
|
5
|
-
<img
|
10
|
+
<img
|
11
|
+
src="{{ page.image | uri_escape }}"
|
12
|
+
class="img-fluid"
|
13
|
+
loading="{{ embed.loading }}"
|
14
|
+
referrerpolicy="{{ embed.referrerpolicy }}" />
|
6
15
|
{%- endif -%}
|
7
16
|
|
8
17
|
{%- if page.audio -%}
|
9
|
-
<audio
|
18
|
+
<audio
|
19
|
+
{% if embed.controls %}controls{% endif %}
|
20
|
+
class="w-100"
|
21
|
+
src="{{ page.audio | uri_escape }}"/>
|
10
22
|
{%- endif -%}
|
11
23
|
|
12
|
-
<
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
24
|
+
<header class="card-body">
|
25
|
+
<h1 class="lead">{{ page.title | escape_once | newline_to_br }}</h1>
|
26
|
+
{% if page.description %}
|
27
|
+
<p>
|
28
|
+
{{- page.description | escape_once | newline_to_br -}}
|
29
|
+
</p>
|
30
|
+
{% endif %}
|
31
|
+
|
32
|
+
<a
|
33
|
+
class="card-link"
|
34
|
+
rel="{{ embed.rel | join: " "}}"
|
35
|
+
target="{{ embed.target }}"
|
36
|
+
referrerpolicy="{{ embed.referrerpolicy }}"
|
37
|
+
href="{{ page.url | uri_escape }}">
|
38
|
+
{{- page.url -}}
|
39
|
+
</a>
|
40
|
+
</header>
|
19
41
|
</article>
|
data/lib/jekyll/embed/content.rb
CHANGED
@@ -14,16 +14,13 @@ module Jekyll
|
|
14
14
|
# @return [String]
|
15
15
|
def embed(content)
|
16
16
|
Nokogiri::HTML5.fragment(content).tap do |html|
|
17
|
-
html.css('p > a
|
18
|
-
next unless a.parent.children.
|
17
|
+
html.css('p > a').each do |a|
|
18
|
+
next unless a.parent.children.size == 1
|
19
|
+
next unless a['href'] == a.text.strip
|
19
20
|
|
20
|
-
|
21
|
+
embed = Jekyll::Embed.embed a['href']
|
21
22
|
|
22
|
-
next
|
23
|
-
|
24
|
-
embed = Jekyll::Embed.embed url
|
25
|
-
|
26
|
-
next if url == embed
|
23
|
+
next if a['href'] == embed
|
27
24
|
|
28
25
|
a.parent.replace embed
|
29
26
|
end
|
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
|
@@ -62,8 +62,9 @@ module Jekyll
|
|
62
62
|
encrypted-media execution-while-not-rendered execution-while-out-of-viewport fullscreen gamepad geolocation gyroscope layout-animations legacy-image-formats magnetometer microphone midi navigation-override oversized-images payment picture-in-picture publickey-credentials-get speaker-selection sync-xhr usb screen-wake-lock web-share xr-spatial-tracking].freeze
|
63
63
|
|
64
64
|
# Templates
|
65
|
-
INCLUDE_OGP = '{% include ogp.html
|
66
|
-
INCLUDE_FALLBACK = '{% include fallback.html
|
65
|
+
INCLUDE_OGP = '{% include ogp.html %}'
|
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
|
@@ -79,12 +80,14 @@ module Jekyll
|
|
79
80
|
'scrub' => %w[form input textarea button fieldset select option optgroup canvas area map],
|
80
81
|
'attributes' => {
|
81
82
|
'referrerpolicy' => 'strict-origin-when-cross-origin',
|
82
|
-
'sandbox' => %w[allow-scripts allow-popups],
|
83
|
+
'sandbox' => %w[allow-scripts allow-popups allow-popups-to-escape-sandbox],
|
83
84
|
'allow' => %w[fullscreen; gyroscope; picture-in-picture; clipboard-write;],
|
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
|
-
|
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
|
@@ -226,7 +232,7 @@ module Jekyll
|
|
226
232
|
rescue ArgumentError
|
227
233
|
Jekyll.logger.warn 'Invalid contents (OGP):', url
|
228
234
|
nil
|
229
|
-
rescue OGP::MalformedSourceError, OGP::MissingAttributeError, Faraday::Error
|
235
|
+
rescue LL::ParserError, OGP::MalformedSourceError, OGP::MissingAttributeError, Faraday::Error
|
230
236
|
nil
|
231
237
|
end
|
232
238
|
|
@@ -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
|
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
|
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
|
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
|
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'] =
|
329
|
+
element['src'] = UrlPrivacy.clean(element['src'])
|
324
330
|
end
|
325
331
|
|
326
332
|
html.css('[href]').each do |element|
|
327
|
-
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,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.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -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
|