jekyll-embed-urls 0.1.0 → 0.2.0

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: 35c0f485187e769d27b2459ff7a12c24ed913ae2eff55ac9ba4867ca50717454
4
- data.tar.gz: 27653e6672c5dfd60836db89f35a2c4ec7088ce1b65eced7f8a0be89564e586e
3
+ metadata.gz: 38bf8e56a0b446544b161c172f12b013b89b9f30907888cc57eaef2a9c9abc1b
4
+ data.tar.gz: 765fa0635ce932982fc14279fc007127883aab30c456887b9a166160477855c5
5
5
  SHA512:
6
- metadata.gz: 9efcd5d53d829267f0f58c3f44eb7ffd23da559fea2e8af102300beb7038b57acb0a2f5c8e263bd3ea2c54e7b8b708feb8eff18b9fcab665bb8cc007072001f8
7
- data.tar.gz: 1cc3c943f041820ca211b63561897404ae24e8d0da2889b200a0041c41859b203f452497c41575f4187374ec3339919adf46228f851ac4e82e3c0dc95dcd5cd7
6
+ metadata.gz: 6434287bd81791b0420c0d80b995d37222c80370db283f2297b7b9542792f069315621d59e8de1b79aca2597381cc875c0a0313b6e0aa8130b7defb50fe03ab7
7
+ data.tar.gz: 5a41d00060687e833e82672ffbd44dfc99aa67b3ff9ab42167a5db58085a96b0a1c538f1203396ba6c102e28c7b98f77e48a1e0b5832433fa1115e3b2f2a1d9d
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.2.0
4
+
5
+ * Use a sandboxed iframe
6
+
3
7
  ## v0.1.0
4
8
 
5
9
  * Supports OEmbed!
data/README.md CHANGED
@@ -46,6 +46,9 @@ https://www.invidio.us/watch?v=XYHnd4boUoM
46
46
  **Note:** The URL can be anywhere, at the start, end or between
47
47
  paragraphs but it needs to be in its own block of text.
48
48
 
49
+ **Another note:** [Invidious doesn't support OEmbed
50
+ yet](https://github.com/omarroth/invidious/issues/1222) :P
51
+
49
52
 
50
53
  ## Contributing
51
54
 
@@ -1,8 +1,6 @@
1
1
  require 'oembed'
2
+ require 'cgi'
2
3
 
3
- OEmbed::Providers.register_all
4
- OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery,
5
- OEmbed::Providers::Noembed)
6
4
 
7
5
  # Process the content of documents before rendering them to find URLs in
8
6
  # a block.
@@ -18,25 +16,44 @@ Jekyll::Hooks.register :site, :pre_render do |site|
18
16
  # Split texts by markdown blocks
19
17
  doc.content = doc.content.split("\n\n").map do |p|
20
18
  # Only process lines with URLs
21
- if %r{https?://} =~ p
19
+ if %r{\Ahttps?://} =~ p
22
20
  # Remove empty characters
23
21
  p.strip!
24
22
 
23
+ # @see {https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox}
24
+ same_origin = p.start_with? site.config['url']
25
+
25
26
  Jekyll.logger.debug "Finding OEmbed content for #{p}"
26
27
  # Cache the results
27
28
  cache.getset(p) do
28
29
  Jekyll.logger.debug "=> Not cached, obtaining..."
29
30
 
30
- OEmbed::Providers.get(p).html
31
- # If the URL doesn't support OEmbed just return an external
32
- # link.
31
+ result = OEmbed::Providers.get(p)
32
+
33
+ # Return a sandboxed iframe with the size of the HTML. We
34
+ # only allow scripts to run inside the iframe and nothing
35
+ # else.
36
+ <<~IFRAME
37
+ <iframe
38
+ referrerpolicy="no-referrer"
39
+ sandbox="allow-scripts #{same_origin ? '' : 'allow-same-origin'}"
40
+ style="min-width:#{result.width}px;min-height:#{result.height || 0}px"
41
+ srcdoc="#{CGI.escape_html result.html}"
42
+ ></iframe>
43
+ IFRAME
44
+
45
+ result.html
33
46
  rescue OEmbed::NotFound => e
34
- Jekyll.logger.warn "#{p} is not oembeddable, showing as URL"
47
+ # If the URL doesn't support OEmbed just return an external
48
+ # link.
49
+ #
50
+ # TODO: Fetch information with OGP and render a template.
51
+ Jekyll.logger.warn "#{p} is not oembeddable or URL can't be fetched, showing as URL"
35
52
 
36
53
  "<a href=\"#{p}\" target=\"_blank\">#{p}</a>"
37
54
  end
38
- # Otherwise return the original block
39
55
  else
56
+ # Otherwise return the original block
40
57
  p
41
58
  end
42
59
  # Rebuild the content
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-06 00:00:00.000000000 Z
11
+ date: 2020-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: oembed
28
+ name: ruby-oembed
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
@@ -61,7 +61,7 @@ metadata:
61
61
  source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-embed-urls
62
62
  changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-embed-urls/-/blob/master/CHANGELOG.md
63
63
  documentation_uri: https://rubydoc.info/gems/jekyll-embed-urls
64
- post_install_message:
64
+ post_install_message:
65
65
  rdoc_options:
66
66
  - "--title"
67
67
  - jekyll-embed-urls - Embed URL previsualization in Jekyll posts
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '2'
79
+ version: '2.6'
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - ">="
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubygems_version: 3.0.3
87
- signing_key:
87
+ signing_key:
88
88
  specification_version: 4
89
89
  summary: Embed URL previsualization in Jekyll posts
90
90
  test_files: []