jekyll-spaceship 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-spaceship/processors/media-processor.rb +72 -81
- data/lib/jekyll-spaceship/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbba69bcf95b309c36da702cce9670212f7a32985e2522f13b06fdc0058e0b60
|
4
|
+
data.tar.gz: 679ee30cad6abfe6c6fb271e3816bff2e16f931b94492d0e0223f4dba11263f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 207137e6fedec9521c2cde3a3215cf7f1ccbc81f6ce0385c385a1c48d31a1ba7d03b3c532e0cbde80ce2f8d33e79a770d299d64cc436acddfc03ed651a2e9fc4
|
7
|
+
data.tar.gz: 1c78e2e73e99f7c3e007e3cbcea683b1d4a4db5771737530865be9262d42adf5617e6d7b9cb9931b4947937fdc64d927bf38967121b2dc98d1107d5bec01cace
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'uri'
|
4
|
+
require "nokogiri"
|
4
5
|
|
5
6
|
module Jekyll::Spaceship
|
6
7
|
class MediaProcessor < Processor
|
@@ -18,23 +19,29 @@ module Jekyll::Spaceship
|
|
18
19
|
}
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
def on_handle_html(content)
|
23
|
+
# use nokogiri to parse html content
|
24
|
+
doc = Nokogiri::HTML(content)
|
25
|
+
# handle each img tag
|
26
|
+
doc.css('img').each do |element|
|
27
|
+
handle_normal_audio(element)
|
28
|
+
handle_normal_video(element)
|
29
|
+
handle_youtube(element)
|
30
|
+
handle_vimeo(element)
|
31
|
+
handle_dailymotion(element)
|
32
|
+
handle_spotify(element)
|
33
|
+
handle_soundcloud(element)
|
34
|
+
end
|
35
|
+
doc.to_html
|
29
36
|
end
|
30
37
|
|
31
38
|
# Examples:
|
32
39
|
# ![audio](//www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3)
|
33
40
|
# ![audio](//www.expample.com/examples/t-rex-roar.mp3?autoplay=true&loop=true)
|
34
|
-
def handle_normal_audio(
|
35
|
-
handle_media(
|
41
|
+
def handle_normal_audio(element)
|
42
|
+
handle_media(element, {
|
36
43
|
media_type: 'audio',
|
37
|
-
host: '(https
|
44
|
+
host: '(https?:\\/\\/)?.*\\/',
|
38
45
|
id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))',
|
39
46
|
})
|
40
47
|
end
|
@@ -44,10 +51,10 @@ module Jekyll::Spaceship
|
|
44
51
|
# ![video](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
|
45
52
|
# ![video](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
|
46
53
|
# ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
|
47
|
-
def handle_normal_video(
|
48
|
-
handle_media(
|
54
|
+
def handle_normal_video(element)
|
55
|
+
handle_media(element, {
|
49
56
|
media_type: 'iframe',
|
50
|
-
host: '(https
|
57
|
+
host: '(https?:\\/\\/)?.*\\/',
|
51
58
|
id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))'
|
52
59
|
})
|
53
60
|
end
|
@@ -56,8 +63,8 @@ module Jekyll::Spaceship
|
|
56
63
|
# ![youtube](https://www.youtube.com/watch?v=XA2WjJbmmoM "title")
|
57
64
|
# ![youtube](http://www.youtube.com/embed/w-m_yZCLF5Q)
|
58
65
|
# ![youtube](//youtu.be/mEP3YXaSww8?height=100%&width=400)
|
59
|
-
def handle_youtube(
|
60
|
-
handle_media(
|
66
|
+
def handle_youtube(element)
|
67
|
+
handle_media(element, {
|
61
68
|
media_type: 'iframe',
|
62
69
|
host: '(https?:)?\\/\\/.*youtu.*',
|
63
70
|
id: '(?<=\\?v\\=|embed\\/|\\.be\\/)([a-zA-Z0-9\\_\\-]+)',
|
@@ -68,8 +75,8 @@ module Jekyll::Spaceship
|
|
68
75
|
# Examples:
|
69
76
|
# ![vimeo](https://vimeo.com/263856289)
|
70
77
|
# ![vimeo](https://vimeo.com/263856289?height=100%&width=400)
|
71
|
-
def handle_vimeo(
|
72
|
-
handle_media(
|
78
|
+
def handle_vimeo(element)
|
79
|
+
handle_media(element, {
|
73
80
|
media_type: 'iframe',
|
74
81
|
host: '(https?:)?\\/\\/vimeo\\.com\\/',
|
75
82
|
id: '([0-9]+)',
|
@@ -80,8 +87,8 @@ module Jekyll::Spaceship
|
|
80
87
|
# Examples:
|
81
88
|
# ![dailymotion](https://www.dailymotion.com/video/x7tgcev)
|
82
89
|
# ![dailymotion](https://dai.ly/x7tgcev?height=100%&width=400)
|
83
|
-
def handle_dailymotion(
|
84
|
-
handle_media(
|
90
|
+
def handle_dailymotion(element)
|
91
|
+
handle_media(element, {
|
85
92
|
media_type: 'iframe',
|
86
93
|
host: '(https?:)?\\/\\/.*dai.?ly.*',
|
87
94
|
id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)',
|
@@ -92,8 +99,8 @@ module Jekyll::Spaceship
|
|
92
99
|
# Examples:
|
93
100
|
# ![spotify](//open.spotify.com/track/4Dg5moVCTqxAb7Wr8Dq2T5)
|
94
101
|
# ![spotify](//open.spotify.com/track/37mEkAaqCE7FXMvnlVA8pp?width=400)
|
95
|
-
def handle_spotify(
|
96
|
-
handle_media(
|
102
|
+
def handle_spotify(element)
|
103
|
+
handle_media(element, {
|
97
104
|
media_type: 'iframe',
|
98
105
|
host: '(https?:)?\\/\\/open\\.spotify\\.com\\/track\\/',
|
99
106
|
id: '(?<=track\\/)([a-zA-Z0-9\\_\\-]+)',
|
@@ -104,8 +111,8 @@ module Jekyll::Spaceship
|
|
104
111
|
|
105
112
|
# Examples:
|
106
113
|
# ![soundcloud](//soundcloud.com/aviciiofficial/preview-avicii-vs-lenny)
|
107
|
-
def handle_soundcloud(
|
108
|
-
handle_media(
|
114
|
+
def handle_soundcloud(element)
|
115
|
+
handle_media(element, {
|
109
116
|
media_type: 'iframe',
|
110
117
|
id_from: 'html',
|
111
118
|
host: '(https?:)?\\/\\/soundcloud\\.com\\/.+\\/[^\\?]+',
|
@@ -116,71 +123,53 @@ module Jekyll::Spaceship
|
|
116
123
|
})
|
117
124
|
end
|
118
125
|
|
119
|
-
def handle_media(
|
126
|
+
def handle_media(element, data)
|
120
127
|
host = data[:host]
|
121
|
-
|
128
|
+
src = element.get_attribute('src')
|
129
|
+
title = element.get_attribute('title')
|
130
|
+
id = data[:id_from] === 'html' ? '()' : data[:id]
|
131
|
+
match_data = src.match(/#{host}#{id}\S*/)
|
132
|
+
return if match_data.nil?
|
122
133
|
|
123
134
|
media_type = data[:media_type]
|
124
135
|
base_url = data[:base_url]
|
125
|
-
id = data[:id_from] === 'html'
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
content.scan regex do |match_data|
|
132
|
-
match = match_data[0]
|
133
|
-
ref_name = match_data[1]
|
134
|
-
ref_value = match_data[2]
|
135
|
-
content = content.gsub(match, '')
|
136
|
-
.gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/,
|
137
|
-
"![\1](#{ref_value})")
|
136
|
+
id = data[:id_from] === 'html' \
|
137
|
+
? get_id_from_html(src, data[:id]) \
|
138
|
+
: match_data[2]
|
139
|
+
qs = src.match(/(?<=\?)(\S*?)$/)
|
140
|
+
qs = Hash[URI.decode_www_form(qs.to_s)].reject do |k, v|
|
141
|
+
next true if v == id or v == ''
|
138
142
|
end
|
139
143
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
: match_data[4]
|
147
|
-
title = match_data[6]
|
148
|
-
qs = url.match(/(?<=\?)(\S*?)$/)
|
149
|
-
qs = Hash[URI.decode_www_form(qs.to_s)].reject do |k, v|
|
150
|
-
next true if v == id or v == ''
|
151
|
-
end
|
152
|
-
|
153
|
-
cfg = self.config['default'].clone
|
154
|
-
cfg['id'] = qs['id'] || cfg['id']
|
155
|
-
cfg['class'] = qs['class'] || cfg['class']
|
156
|
-
cfg['style'] = qs['style'] || cfg['style']
|
157
|
-
cfg['id'] = cfg['id'].gsub('{id}', id)
|
158
|
-
cfg['class'] = cfg['class'].gsub('{id}', id)
|
144
|
+
cfg = self.config['default'].clone
|
145
|
+
cfg['id'] = qs['id'] || cfg['id']
|
146
|
+
cfg['class'] = qs['class'] || cfg['class']
|
147
|
+
cfg['style'] = qs['style'] || cfg['style']
|
148
|
+
cfg['id'] = cfg['id'].gsub('{id}', id)
|
149
|
+
cfg['class'] = cfg['class'].gsub('{id}', id)
|
159
150
|
|
160
|
-
|
161
|
-
|
162
|
-
|
151
|
+
cfg['src'] = URI(base_url ? "#{base_url}#{id}" : src).tap do |v|
|
152
|
+
v.query = URI.encode_www_form(qs) if qs.size > 0
|
153
|
+
end
|
163
154
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
end
|
178
|
-
self.handled = true
|
155
|
+
case media_type
|
156
|
+
when 'audio'
|
157
|
+
cfg['autoplay'] = qs['autoplay'] || data[:autoplay] || cfg['autoplay']
|
158
|
+
cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
|
159
|
+
cfg['style'] += ';display: none;' if qs['hidden']
|
160
|
+
handle_audio(element, { cfg: cfg })
|
161
|
+
when 'iframe'
|
162
|
+
cfg['title'] = title
|
163
|
+
cfg['width'] = qs['width'] || data[:width] || cfg['width']
|
164
|
+
cfg['height'] = qs['height'] || data[:height] || cfg['height']
|
165
|
+
cfg['frameborder'] = qs['frameborder'] || cfg['frameborder']
|
166
|
+
cfg['allow'] ||= cfg['allow']
|
167
|
+
handle_iframe(element, { cfg: cfg })
|
179
168
|
end
|
180
|
-
|
169
|
+
self.handled = true
|
181
170
|
end
|
182
171
|
|
183
|
-
def handle_audio(
|
172
|
+
def handle_audio(element, data)
|
184
173
|
cfg = data[:cfg]
|
185
174
|
html = "<audio"\
|
186
175
|
" id=\"#{cfg['id']}\""\
|
@@ -194,10 +183,11 @@ module Jekyll::Spaceship
|
|
194
183
|
" Here is a <a href=\"#{cfg['src']}\">link to download the audio</a>"\
|
195
184
|
"instead. </p>"\
|
196
185
|
"</audio>"
|
197
|
-
|
186
|
+
doc = Nokogiri::XML(html)
|
187
|
+
element.replace(doc.children.first)
|
198
188
|
end
|
199
189
|
|
200
|
-
def handle_iframe(
|
190
|
+
def handle_iframe(element, data)
|
201
191
|
cfg = data[:cfg]
|
202
192
|
html = "<iframe"\
|
203
193
|
" id=\"#{cfg['id']}\""\
|
@@ -211,7 +201,8 @@ module Jekyll::Spaceship
|
|
211
201
|
" frameborder=\"#{cfg['frameborder']}\""\
|
212
202
|
" allowfullscreen>"\
|
213
203
|
"</iframe>"
|
214
|
-
|
204
|
+
doc = Nokogiri::XML(html)
|
205
|
+
element.replace(doc.children.first)
|
215
206
|
end
|
216
207
|
|
217
208
|
def get_id_from_html(url, pattern)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-spaceship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffreytse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|