jekyll-embed-urls 0.1.0 → 0.3.3

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +6 -0
  4. data/lib/jekyll-embed-urls.rb +61 -16
  5. metadata +22 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35c0f485187e769d27b2459ff7a12c24ed913ae2eff55ac9ba4867ca50717454
4
- data.tar.gz: 27653e6672c5dfd60836db89f35a2c4ec7088ce1b65eced7f8a0be89564e586e
3
+ metadata.gz: 5e8b338448bae54c12ee6c9119852b2d93859ddd032c242ace46c0515eb2a4eb
4
+ data.tar.gz: fc960acd1bec7c2f189e7c46cf20739026395700827dd7b5f79c6937178c5c0a
5
5
  SHA512:
6
- metadata.gz: 9efcd5d53d829267f0f58c3f44eb7ffd23da559fea2e8af102300beb7038b57acb0a2f5c8e263bd3ea2c54e7b8b708feb8eff18b9fcab665bb8cc007072001f8
7
- data.tar.gz: 1cc3c943f041820ca211b63561897404ae24e8d0da2889b200a0041c41859b203f452497c41575f4187374ec3339919adf46228f851ac4e82e3c0dc95dcd5cd7
6
+ metadata.gz: db3a88054e7716581d5b87dbf302138331e7e8b11571946d0389eb93c9e2cdc5d9b3e5212cfe7af941d7d9346893e69b80c26d5aabec717d12b0ff4cd94a69b9
7
+ data.tar.gz: f5ef11ac9fa6b6ab8d0826cb0d024ff4a01de43645a7123e4b28832f29a7a61eef332004646618834fa80f2f7f2bb870efe074cd32200112364da3cc143c3adc
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.3.3
4
+
5
+ * Add `allow-popups` to sandbox so you can open links in a new window.
6
+
7
+ ## v0.3.2
8
+
9
+ * Rescue `OEmbed::Error`
10
+
11
+ ## v0.3.1
12
+
13
+ * Put link inside a paragraph so markdown ignores the HTML
14
+
15
+ ## v0.3.0
16
+
17
+ * Reuse the iframe and sandbox it if the embed code contains one
18
+
19
+ * Use a Referrer-Policy
20
+
21
+ https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
22
+
23
+ https://web.dev/referrer-best-practices/
24
+
25
+ ## v0.2.0
26
+
27
+ * Use a sandboxed iframe
28
+
3
29
  ## v0.1.0
4
30
 
5
31
  * 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
 
@@ -55,6 +58,9 @@ intended to be a safe, welcoming space for collaboration, and
55
58
  contributors are expected to adhere to the [Sutty code of
56
59
  conduct](https://sutty.nl/en/code-of-conduct/).
57
60
 
61
+ If you like our plugins, [please consider
62
+ donating](https://donaciones.sutty.nl/en/)!
63
+
58
64
  ## License
59
65
 
60
66
  The gem is available as free software under the terms of the GPL3
@@ -1,4 +1,16 @@
1
1
  require 'oembed'
2
+ require 'cgi'
3
+ require 'oga'
4
+
5
+ # TODO: We tested several of the mainstream embedable contents (YT, IG,
6
+ # Twitter) and specially IG and Twitter just want to take over the page
7
+ # to set their own size, also send metrics. So they won't work on a
8
+ # sandboxed iframe, which we were expecting, but they also won't be
9
+ # comfortable for visitors to use. We're planning on using OGP and
10
+ # render our own partials (configurable) for this. This way everything
11
+ # is safer and the embedded content even adapts to the site's design.
12
+ #
13
+ # So, expect a major refactoring!
2
14
 
3
15
  OEmbed::Providers.register_all
4
16
  OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery,
@@ -9,35 +21,68 @@ OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery,
9
21
  Jekyll::Hooks.register :site, :pre_render do |site|
10
22
  # Cache results
11
23
  cache ||= Jekyll::Cache.new('Jekyll::OEmbed::Urls')
24
+ # TODO: Make configurable
25
+ referrer_policy = 'strict-origin-when-cross-origin'
12
26
 
13
27
  # Only modify documents to be written
14
28
  site.docs_to_write.each do |doc|
15
29
  # Skip text paragraphs
16
- next unless %r{\n\nhttps?://} =~ doc.content
30
+ # XXX: Find link in first line
31
+ next unless %r{\n\n\s*<?https?://} =~ doc.content
17
32
 
18
33
  # Split texts by markdown blocks
19
34
  doc.content = doc.content.split("\n\n").map do |p|
20
35
  # Only process lines with URLs
21
- if %r{https?://} =~ p
22
- # Remove empty characters
23
- p.strip!
36
+ next p unless %r{\A\s*<?https?://} =~ p
37
+ # Remove empty characters and markdown autolinks
38
+ p = p.strip.tr('<', '').tr('>', '')
39
+
40
+ # @see {https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox}
41
+ same_origin = p.start_with? site.config['url']
42
+
43
+ Jekyll.logger.debug "Finding OEmbed content for #{p}"
44
+ # Cache the results
45
+ cache.getset(p) do
46
+ Jekyll.logger.debug "=> Not cached, obtaining..."
47
+
48
+ result = OEmbed::Providers.get(p)
49
+ sandbox = "allow-scripts allow-popups #{same_origin ? '' : 'allow-same-origin'}"
24
50
 
25
- Jekyll.logger.debug "Finding OEmbed content for #{p}"
26
- # Cache the results
27
- cache.getset(p) do
28
- Jekyll.logger.debug "=> Not cached, obtaining..."
51
+ # If the embed HTML contains an iframe, make sure it has the
52
+ # correct attributes.
53
+ if %r{<iframe } =~ result.html
54
+ html = Oga.parse_html result.html
29
55
 
30
- OEmbed::Providers.get(p).html
56
+ html.css('iframe').each do |iframe|
57
+ iframe.attributes.delete_if do |attr|
58
+ %w[width height].include? attr.name
59
+ end
60
+
61
+ iframe.attributes << Oga::XML::Attribute.new(name: 'sandbox', value: sandbox)
62
+ iframe.attributes << Oga::XML::Attribute.new(name: 'referrerpolicy', value: referrer_policy)
63
+ end
64
+
65
+ html.to_xml
66
+ else
67
+ # Return a sandboxed iframe with the size of the HTML. We
68
+ # only allow scripts to run inside the iframe and nothing
69
+ # else.
70
+ <<~IFRAME
71
+ <iframe
72
+ referrerpolicy="#{referrer_policy}"
73
+ sandbox="#{sandbox}"
74
+ style="min-width:#{result.width}px;min-height:#{result.height || 0}px"
75
+ srcdoc="#{CGI.escape_html result.html}"></iframe>
76
+ IFRAME
77
+ end
78
+ rescue OEmbed::Error => e
31
79
  # If the URL doesn't support OEmbed just return an external
32
80
  # link.
33
- rescue OEmbed::NotFound => e
34
- Jekyll.logger.warn "#{p} is not oembeddable, showing as URL"
81
+ #
82
+ # TODO: Fetch information with OGP and render a template.
83
+ Jekyll.logger.warn "#{p} is not oembeddable or URL can't be fetched, showing as URL: #{e}"
35
84
 
36
- "<a href=\"#{p}\" target=\"_blank\">#{p}</a>"
37
- end
38
- # Otherwise return the original block
39
- else
40
- p
85
+ %(<p><a href="#{p}" target="_blank" referrerpolicy="#{referrer_policy}">#{p}</a></p>)
41
86
  end
42
87
  # Rebuild the content
43
88
  end.join("\n\n")
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.3.3
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-10-30 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
  - - "~>"
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oga
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.15'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.15'
41
55
  description: Replaces URLs for their previsualization in Jekyll posts
42
56
  email:
43
57
  - f@sutty.nl
@@ -61,7 +75,7 @@ metadata:
61
75
  source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-embed-urls
62
76
  changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-embed-urls/-/blob/master/CHANGELOG.md
63
77
  documentation_uri: https://rubydoc.info/gems/jekyll-embed-urls
64
- post_install_message:
78
+ post_install_message:
65
79
  rdoc_options:
66
80
  - "--title"
67
81
  - jekyll-embed-urls - Embed URL previsualization in Jekyll posts
@@ -76,15 +90,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
90
  requirements:
77
91
  - - "~>"
78
92
  - !ruby/object:Gem::Version
79
- version: '2'
93
+ version: '2.6'
80
94
  required_rubygems_version: !ruby/object:Gem::Requirement
81
95
  requirements:
82
96
  - - ">="
83
97
  - !ruby/object:Gem::Version
84
98
  version: '0'
85
99
  requirements: []
86
- rubygems_version: 3.0.3
87
- signing_key:
100
+ rubygems_version: 3.1.2
101
+ signing_key:
88
102
  specification_version: 4
89
103
  summary: Embed URL previsualization in Jekyll posts
90
104
  test_files: []