jekyll-embed-urls 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -0
- data/lib/jekyll-embed-urls.rb +26 -9
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38bf8e56a0b446544b161c172f12b013b89b9f30907888cc57eaef2a9c9abc1b
|
4
|
+
data.tar.gz: 765fa0635ce932982fc14279fc007127883aab30c456887b9a166160477855c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6434287bd81791b0420c0d80b995d37222c80370db283f2297b7b9542792f069315621d59e8de1b79aca2597381cc875c0a0313b6e0aa8130b7defb50fe03ab7
|
7
|
+
data.tar.gz: 5a41d00060687e833e82672ffbd44dfc99aa67b3ff9ab42167a5db58085a96b0a1c538f1203396ba6c102e28c7b98f77e48a1e0b5832433fa1115e3b2f2a1d9d
|
data/CHANGELOG.md
CHANGED
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
|
|
data/lib/jekyll-embed-urls.rb
CHANGED
@@ -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{
|
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)
|
31
|
-
|
32
|
-
|
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
|
-
|
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.
|
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-
|
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: []
|