jekyll-embed-urls 0.4.5 → 0.5.0

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: ec91f328eea6a0559fa41ffbfec9bccd3e3a19662369c36331cfaa8d6dc8d4fc
4
- data.tar.gz: 47b8560d986e6083de1538ab0a372756705579af46d8b4d725051f2f52ad15f9
3
+ metadata.gz: 3c93e9e9f911c9988829cddbd88afd919995cfd55fd51a21e917e81f7044ddbf
4
+ data.tar.gz: 748730c8fb90b9f37f02b5cb7461a08df1502a1700a02748837450451ab0627a
5
5
  SHA512:
6
- metadata.gz: 5cb5c650b7e79ec5ff0ea074acdbf2334dce4f310a1cc670613f31313dce81368a8a216d468bd73762fab08a13ccfe34d5f5d6887602d8fcc80f07dba5e8c120
7
- data.tar.gz: f3b16a6d48a274cdd83fa710d5e0e7cec88bd281bd578dba5dd7bccba3d509f9d3a7ecb124f058c73e11687ea273d56c4194599ad552cdf35e4aac3c1b033420
6
+ metadata.gz: 2ac2e6bd99303c206cbcbe865d91f39cfc553c3d5f02d36c1ec88760a2fc757b805235f6054ae7f6d7d694d69e4f94af18a4202f635717ae13541cb9e491786c
7
+ data.tar.gz: f85276cd1f18db800686ff00f1cd00a83535c0c16a968b31175e6c4ba8f02492f791fdfd714de7657ac175d78da023f23a716bde46da55497ec2ac6d4a107897
@@ -1,17 +1,17 @@
1
- <article class="fallback">
2
- {%- if page.image -%}
3
- <img referrerpolicy="{{ embed.referrerpolicy }}" loading="{{ embed.loading }}" src="{{ page.image }}" class="img-fluid" />
4
- {%- endif -%}
1
+ {% if page.url contains "//archive.org/" or page.url contains "//www.archive.org/" %}
2
+ <iframe src="{{ page.url | replace: "/details/", "/embed/" | uri_escape }}"></iframe>
3
+ {% else %}
4
+ <article class="fallback" lang="{{ page.locale }}">
5
+ {%- if page.image -%}
6
+ <img src="{{ page.image | uri_escape }}" class="img-fluid" />
7
+ {%- endif -%}
5
8
 
6
- <h1>{{ page.title }}</h1>
7
- <p class="lead">{{ page.description }}</p>
8
- <p><small>
9
- <a
10
- href="{{ page.url }}"
11
- referrerpolicy="{{ embed.referrerpolicy }}"
12
- target="{{ embed.target }}"
13
- rel="{{ embed.rel }}">
14
- {{ page.url }}
15
- </a>
16
- </small><p>
17
- </article>
9
+ <h1>{{ page.title }}</h1>
10
+ <p class="lead">{{ page.description }}</p>
11
+ <p>
12
+ <small>
13
+ <a href="{{ page.url | uri_escape }}">{{ page.url }}</a>
14
+ </small>
15
+ </p>
16
+ </article>
17
+ {% endif %}
data/_includes/ogp.html CHANGED
@@ -1,23 +1,19 @@
1
1
  <article class="ogp" lang="{{ page.locale }}">
2
2
  {%- if page.video -%}
3
- <video poster="{{ page.image }}" class="img-fluid" {{ embed.controls }} src="{{ page.video }}"/>
3
+ <video poster="{{ page.image | uri_escape }}" class="img-fluid" src="{{ page.video | uri_escape }}"/>
4
4
  {%- elsif page.image -%}
5
- <img referrerpolicy="{{ embed.referrerpolicy }}" loading="{{ embed.loading }}" src="{{ page.image }}" class="img-fluid" />
5
+ <img src="{{ page.image | uri_escape }}" class="img-fluid" />
6
6
  {%- endif -%}
7
7
 
8
8
  {%- if page.audio -%}
9
- <audio class="img-fluid" {{ embed.controls }} src="{{ page.audio }}"/>
9
+ <audio class="img-fluid" src="{{ page.audio | uri_escape }}"/>
10
10
  {%- endif -%}
11
11
 
12
12
  <h1>{{ page.title }}</h1>
13
13
  <p class="lead">{{ page.description }}</p>
14
- <p><small>
15
- <a
16
- href="{{ page.url }}"
17
- referrerpolicy="{{ embed.referrerpolicy }}"
18
- target="{{ embed.target }}"
19
- rel="{{ embed.rel }}">
20
- {{ page.url }}
21
- </a>
22
- </small><p>
14
+ <p>
15
+ <small>
16
+ <a href="{{ page.url | uri_escape }}">{{ page.url }}</a>
17
+ </small>
18
+ </p>
23
19
  </article>
data/lib/jekyll/embed.rb CHANGED
@@ -157,6 +157,7 @@ module Jekyll
157
157
  raise URI::Error unless url.start_with? 'http'
158
158
 
159
159
  # Just to verify the URL is valid
160
+ # TODO: Use Addressable
160
161
  URI.parse url
161
162
 
162
163
  oembed(url) || ogp(url) || fallback(url)
@@ -178,15 +179,13 @@ module Jekyll
178
179
  # @param [String] URL
179
180
  # @return [String,NilClass] Sanitized HTML or nil
180
181
  def oembed(url)
181
- cache.getset(url) do
182
+ cache.getset("oembed+#{url}") do
182
183
  oembed = OEmbed::Providers.get url
183
184
 
184
185
  # Prevent caching of nil?
185
186
  raise OEmbed::Error unless oembed.respond_to? :html
186
187
 
187
- # Cleanup. We don't allow running remote scripts locally,
188
- # period.
189
- cleanup(Loofah.fragment(oembed.html).scrub!(:prune), url).to_s
188
+ cleanup oembed.html, url
190
189
  end
191
190
  rescue OEmbed::Error
192
191
  nil
@@ -196,12 +195,12 @@ module Jekyll
196
195
  # @param [String] URL
197
196
  # @return [String,NilClass]
198
197
  def ogp(url)
199
- cache.getset(url) do
198
+ cache.getset("ogp+#{url}") do
200
199
  ogp = OGP::OpenGraph.new get(url).body
201
200
  context = info.dup
202
201
  context[:registers][:page] = payload['page'] = ogp.data
203
202
 
204
- ogp_template.render! payload, context
203
+ cleanup ogp_template.render!(payload, context), url
205
204
  end
206
205
  rescue OGP::MalformedSourceError, OGP::MissingAttributeError, Faraday::Error
207
206
  nil
@@ -209,7 +208,7 @@ module Jekyll
209
208
 
210
209
  # Try something
211
210
  def fallback(url)
212
- cache.getset(url) do
211
+ cache.getset("fallback+#{url}") do
213
212
  html = Nokogiri::HTML.fragment get(url).body
214
213
  element = html.css('article').first
215
214
  element ||= html.css('section').first
@@ -223,10 +222,11 @@ module Jekyll
223
222
  'title' => text(title),
224
223
  'description' => text(description),
225
224
  'url' => url,
226
- 'image' => element&.css('img')&.first&.public_send(:[], 'src')
225
+ 'image' => element&.css('img')&.first&.public_send(:[], 'src'),
226
+ 'locale' => html.css('html')&.first&.public_send(:[], 'lang')
227
227
  }
228
228
 
229
- fallback_template.render! payload, context
229
+ cleanup fallback_template.render!(payload, context), url
230
230
  end
231
231
  rescue Faraday::Error, Nokogiri::SyntaxError
232
232
  nil
@@ -252,7 +252,12 @@ module Jekyll
252
252
  end
253
253
  end
254
254
 
255
- def cleanup(html, url)
255
+ # @params :html_fragment [String]
256
+ # @params :url [String]
257
+ # @return [String]
258
+ def cleanup(html_fragment, url)
259
+ html = Loofah.fragment(html_fragment).scrub!(:prune)
260
+
256
261
  # Add our own attributes
257
262
  html.css('iframe').each do |iframe|
258
263
  IFRAME_ATTRIBUTES.each do |attr|
@@ -291,8 +296,8 @@ module Jekyll
291
296
  element['href'] = CGI.escapeHTML(UrlPrivacy.clean(CGI.unescapeHTML(element['href'])))
292
297
  end
293
298
 
294
- # Return the cleaned up HTML
295
- html
299
+ # Return the cleaned up HTML as a String
300
+ html.to_s
296
301
  end
297
302
 
298
303
  def text(node)
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.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-24 00:00:00.000000000 Z
11
+ date: 2022-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll