jekyll-spaceship 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -18
- data/jekyll-spaceship.gemspec +1 -1
- data/lib/jekyll-spaceship/cores/config.rb +1 -1
- data/lib/jekyll-spaceship/processors/media-processor.rb +234 -0
- data/lib/jekyll-spaceship/version.rb +1 -1
- metadata +5 -4
- data/lib/jekyll-spaceship/processors/video-processor.rb +0 -139
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 989c96c9ba4f7b3d1ec891d43022360ab1bea0a4de2956e8a94c24c927df6ca1
|
4
|
+
data.tar.gz: 3aa37c0d529d883e2cef637556d65f65d31e9a5c8ee304ca2a2ee01de11ac527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7bbab4048b639e86cf01e88132c4b9de13acf9651667bcefc15eaaae6c57a3663b69498ebf6172037268ecb63a456a8cf53c751036717f471a8e060a7b5a14b
|
7
|
+
data.tar.gz: 56aab57a999fd3604f1b95475662478c8520ab703a9ae2405f863072c92c012cb1dec094814d17d6e1696ce2d3eea7fb0987e78a77a6c7a8465b95db61826702
|
data/README.md
CHANGED
@@ -107,11 +107,14 @@ Spaceship is a minimalistic, powerful and extremely customizable [Jekyll](https:
|
|
107
107
|
- [2.2 How to use?](#22-how-to-use)
|
108
108
|
- [3. PlantUML Usage](#3-plantuml-usage)
|
109
109
|
- [4. Mermaid Usage](#4-mermaid-usage)
|
110
|
-
- [5.
|
110
|
+
- [5. Media Usage](#5-media-usage)
|
111
111
|
- [5.1 Youtube Usage](#youtube-usage)
|
112
112
|
- [5.2 Vimeo Usage](#vimeo-usage)
|
113
113
|
- [5.3 DailyMotion Usage](#dailymotion-usage)
|
114
|
-
- [5.4
|
114
|
+
- [5.4 Spotify Usage](#spotify-usage)
|
115
|
+
- [5.5 SoundCloud Usage](#soundcloud-usage)
|
116
|
+
- [5.6 General Video Usage](#general-video-usage)
|
117
|
+
- [5.7 General Audio Usage](#general-audio-usage)
|
115
118
|
- [6. Hybrid HTML with Markdown](#6-hybrid-html-with-markdown)
|
116
119
|
- [7. Markdown Polyfill](#7-markdown-polyfill)
|
117
120
|
- [7.1 Escape Ordered List](#71-escape-ordered-list)
|
@@ -162,7 +165,7 @@ jekyll-spaceship:
|
|
162
165
|
- plantuml-processor
|
163
166
|
- mermaid-processor
|
164
167
|
- polyfill-processor
|
165
|
-
-
|
168
|
+
- media-processor
|
166
169
|
- emoji-processor
|
167
170
|
- element-processor
|
168
171
|
mathjax-processor:
|
@@ -194,14 +197,14 @@ jekyll-spaceship:
|
|
194
197
|
config:
|
195
198
|
theme: default
|
196
199
|
src: https://mermaid.ink/svg/
|
197
|
-
|
200
|
+
media-processor:
|
198
201
|
default:
|
199
|
-
id: '
|
200
|
-
class: '
|
202
|
+
id: 'media-{id}'
|
203
|
+
class: 'media'
|
201
204
|
width: '100%'
|
202
205
|
height: 350
|
203
|
-
|
204
|
-
style: 'max-width: 600px'
|
206
|
+
frameborder: 0
|
207
|
+
style: 'max-width: 600px; outline: none;'
|
205
208
|
allow: 'encrypted-media; picture-in-picture'
|
206
209
|
emoji-processor:
|
207
210
|
css:
|
@@ -705,25 +708,31 @@ Code above would be parsed as:
|
|
705
708
|
|
706
709
|
![Mermaid Diagram](https://user-images.githubusercontent.com/9413601/85282355-2e317300-b4be-11ea-9c30-8f9d61540d14.png)
|
707
710
|
|
708
|
-
### 5.
|
711
|
+
### 5. Media Usage
|
709
712
|
|
710
|
-
How often did you find yourself googling "**How to embed a video in markdown?**"
|
713
|
+
How often did you find yourself googling "**How to embed a video/audio in markdown?**"
|
711
714
|
|
712
|
-
While its not possible to embed a video in markdown, the best and easiest
|
715
|
+
While its not possible to embed a video/audio in markdown, the best and easiest
|
716
|
+
way is to extract a frame from the video/audio. To add videos/audios to your
|
717
|
+
markdown files easier I developped this tool for you, and it will parse the
|
718
|
+
video/audio link inside the image block automatically.
|
713
719
|
|
714
|
-
**For now, these
|
720
|
+
**For now, these media links parsing are provided:**
|
715
721
|
|
716
722
|
- Youtube
|
717
723
|
- Vimeo
|
718
724
|
- DailyMotion
|
719
|
-
-
|
725
|
+
- Spotify
|
726
|
+
- SoundCloud
|
727
|
+
- General Video ( mp4 | avi | ogg | ogv | webm | 3gp | flv | mov ... )
|
728
|
+
- General Audio ( mp3 | wav | ogg | mid | midi | aac | wma ... )
|
720
729
|
|
721
|
-
There are two ways to embed a video in your Jekyll blog page:
|
730
|
+
There are two ways to embed a video/audio in your Jekyll blog page:
|
722
731
|
|
723
732
|
Inline-style:
|
724
733
|
|
725
734
|
```markdown
|
726
|
-
![]({
|
735
|
+
![]({media-link})
|
727
736
|
```
|
728
737
|
|
729
738
|
Reference-style:
|
@@ -731,10 +740,10 @@ Reference-style:
|
|
731
740
|
```markdown
|
732
741
|
![][{reference}]
|
733
742
|
|
734
|
-
[{reference}]: {
|
743
|
+
[{reference}]: {media-link}
|
735
744
|
```
|
736
745
|
|
737
|
-
For configuring
|
746
|
+
For configuring media attributes (e.g, width, height), just adding query string to
|
738
747
|
the link as below:
|
739
748
|
|
740
749
|
```markdown
|
@@ -767,6 +776,22 @@ the link as below:
|
|
767
776
|
![](https://dai.ly/x7tgcev?width=100%&height=400)
|
768
777
|
```
|
769
778
|
|
779
|
+
#### Spotify Usage
|
780
|
+
|
781
|
+
```markdown
|
782
|
+
![](http://open.spotify.com/track/4Dg5moVCTqxAb7Wr8Dq2T5)
|
783
|
+
```
|
784
|
+
|
785
|
+
<image width="600" src="https://user-images.githubusercontent.com/9413601/89762618-5d11b000-db23-11ea-81db-35cc3682b234.png">
|
786
|
+
|
787
|
+
#### SoundCloud Usage
|
788
|
+
|
789
|
+
```markdown
|
790
|
+
![](https://soundcloud.com/aviciiofficial/preview-avicii-vs-lenny)
|
791
|
+
```
|
792
|
+
|
793
|
+
<image width="600" src="https://user-images.githubusercontent.com/9413601/89762969-1c666680-db24-11ea-97e3-4340f7fac7ac.png">
|
794
|
+
|
770
795
|
#### General Video Usage
|
771
796
|
|
772
797
|
```markdown
|
@@ -777,6 +802,15 @@ the link as below:
|
|
777
802
|
![](//techslides.com/demos/sample-videos/small.mp4?width=400)
|
778
803
|
```
|
779
804
|
|
805
|
+
#### General Audio Usage
|
806
|
+
|
807
|
+
```markdown
|
808
|
+
![](//www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3)
|
809
|
+
|
810
|
+
![](//www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3?autoplay=1&loop=1)
|
811
|
+
```
|
812
|
+
|
813
|
+
<image width="300" src="https://user-images.githubusercontent.com/9413601/89762143-68181080-db22-11ea-8467-e8b2a8a96ae5.png">
|
780
814
|
|
781
815
|
### 6. Hybrid HTML with Markdown
|
782
816
|
|
@@ -950,7 +984,7 @@ jekyll-spaceship:
|
|
950
984
|
css:
|
951
985
|
- a: # Replce all `a` tags
|
952
986
|
props: #
|
953
|
-
loading: lazy # Replace `
|
987
|
+
loading: lazy # Replace `loading` value to `lazy`
|
954
988
|
```
|
955
989
|
|
956
990
|
In case you want to prevent loading some images/iframes lazily, add
|
data/jekyll-spaceship.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Jekyll::Spaceship::VERSION
|
10
10
|
spec.authors = ["jeffreytse"]
|
11
11
|
spec.email = ["jeffreytse.mail@gmail.com"]
|
12
|
-
spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermaid, emoji, video, youtube, vimeo, dailymotion, etc."
|
12
|
+
spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermaid, emoji, video, audio, youtube, vimeo, dailymotion, spotify, soundcloud, etc."
|
13
13
|
spec.homepage = "https://github.com/jeffreytse/jekyll-spaceship"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Jekyll::Spaceship
|
6
|
+
class MediaProcessor < Processor
|
7
|
+
def self.config
|
8
|
+
{
|
9
|
+
'default' => {
|
10
|
+
'id' => 'media-{id}',
|
11
|
+
'class' => 'media',
|
12
|
+
'width' => '100%',
|
13
|
+
'height' => 350,
|
14
|
+
'frameborder' => 0,
|
15
|
+
'style' => 'max-width: 600px;outline: none',
|
16
|
+
'allow' => 'encrypted-media; picture-in-picture'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_handle_markdown(content)
|
22
|
+
content = handle_normal_audio(content)
|
23
|
+
content = handle_normal_video(content)
|
24
|
+
content = handle_youtube(content)
|
25
|
+
content = handle_vimeo(content)
|
26
|
+
content = handle_dailymotion(content)
|
27
|
+
content = handle_spotify(content)
|
28
|
+
content = handle_soundcloud(content)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Examples:
|
32
|
+
# ![audio](//www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3)
|
33
|
+
# ![audio](//www.expample.com/examples/t-rex-roar.mp3?autoplay=true&loop=true)
|
34
|
+
def handle_normal_audio(content)
|
35
|
+
handle_media(content, {
|
36
|
+
media_type: 'audio',
|
37
|
+
host: '(https?:)?\\/\\/.*\\/',
|
38
|
+
id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))',
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Examples:
|
44
|
+
# ![video](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
|
45
|
+
# ![video](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
|
46
|
+
# ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
|
47
|
+
def handle_normal_video(content)
|
48
|
+
handle_media(content, {
|
49
|
+
media_type: 'iframe',
|
50
|
+
host: '(https?:)?\\/\\/.*\\/',
|
51
|
+
id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))'
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
# Examples:
|
56
|
+
# ![youtube](https://www.youtube.com/watch?v=XA2WjJbmmoM "title")
|
57
|
+
# ![youtube](http://www.youtube.com/embed/w-m_yZCLF5Q)
|
58
|
+
# ![youtube](//youtu.be/mEP3YXaSww8?height=100%&width=400)
|
59
|
+
def handle_youtube(content)
|
60
|
+
handle_media(content, {
|
61
|
+
media_type: 'iframe',
|
62
|
+
host: '(https?:)?\\/\\/.*youtu.*',
|
63
|
+
id: '(?<=\\?v\\=|embed\\/|\\.be\\/)([a-zA-Z0-9\\_\\-]+)',
|
64
|
+
base_url: "https://www.youtube.com/embed/"
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
# Examples:
|
69
|
+
# ![vimeo](https://vimeo.com/263856289)
|
70
|
+
# ![vimeo](https://vimeo.com/263856289?height=100%&width=400)
|
71
|
+
def handle_vimeo(content)
|
72
|
+
handle_media(content, {
|
73
|
+
media_type: 'iframe',
|
74
|
+
host: '(https?:)?\\/\\/vimeo\\.com\\/',
|
75
|
+
id: '([0-9]+)',
|
76
|
+
base_url: "https://player.vimeo.com/video/"
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
# Examples:
|
81
|
+
# ![dailymotion](https://www.dailymotion.com/video/x7tgcev)
|
82
|
+
# ![dailymotion](https://dai.ly/x7tgcev?height=100%&width=400)
|
83
|
+
def handle_dailymotion(content)
|
84
|
+
handle_media(content, {
|
85
|
+
media_type: 'iframe',
|
86
|
+
host: '(https?:)?\\/\\/.*dai.?ly.*',
|
87
|
+
id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)',
|
88
|
+
base_url: "https://www.dailymotion.com/embed/video/"
|
89
|
+
})
|
90
|
+
end
|
91
|
+
|
92
|
+
# Examples:
|
93
|
+
# ![spotify](//open.spotify.com/track/4Dg5moVCTqxAb7Wr8Dq2T5)
|
94
|
+
# ![spotify](//open.spotify.com/track/37mEkAaqCE7FXMvnlVA8pp?width=400)
|
95
|
+
def handle_spotify(content)
|
96
|
+
handle_media(content, {
|
97
|
+
media_type: 'iframe',
|
98
|
+
host: '(https?:)?\\/\\/open\\.spotify\\.com\\/track\\/',
|
99
|
+
id: '(?<=track\\/)([a-zA-Z0-9\\_\\-]+)',
|
100
|
+
base_url: "https://open.spotify.com/embed/track/",
|
101
|
+
height: 80
|
102
|
+
})
|
103
|
+
end
|
104
|
+
|
105
|
+
# Examples:
|
106
|
+
# ![soundcloud](//soundcloud.com/aviciiofficial/preview-avicii-vs-lenny)
|
107
|
+
def handle_soundcloud(content)
|
108
|
+
handle_media(content, {
|
109
|
+
media_type: 'iframe',
|
110
|
+
id_from: 'html',
|
111
|
+
host: '(https?:)?\\/\\/soundcloud\\.com\\/.+\\/[^\\?]+',
|
112
|
+
id: '(?<=soundcloud:\\/\\/sounds:)([0-9]+)',
|
113
|
+
base_url: "https://w.soundcloud.com/player/?url="\
|
114
|
+
"https%3A//api.soundcloud.com/tracks/",
|
115
|
+
height: 125,
|
116
|
+
})
|
117
|
+
end
|
118
|
+
|
119
|
+
def handle_media(content, data)
|
120
|
+
host = data[:host]
|
121
|
+
return content if content.sub(/#{host}/, '').nil?
|
122
|
+
|
123
|
+
media_type = data[:media_type]
|
124
|
+
base_url = data[:base_url]
|
125
|
+
id = data[:id_from] === 'html' ? '()' : data[:id]
|
126
|
+
url = "(#{host}#{id}\\S*)"
|
127
|
+
title = '("(.*)".*){0,1}'
|
128
|
+
|
129
|
+
# pre-handle reference-style links
|
130
|
+
regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/
|
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})")
|
138
|
+
end
|
139
|
+
|
140
|
+
# handle inline-style links
|
141
|
+
regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/
|
142
|
+
content.scan regex do |match_data|
|
143
|
+
url = match_data[2]
|
144
|
+
id = data[:id_from] === 'html' \
|
145
|
+
? get_id_from_html(url, data[:id]) \
|
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)
|
159
|
+
|
160
|
+
cfg['src'] = URI(base_url ? "#{base_url}#{id}" : url).tap do |v|
|
161
|
+
v.query = URI.encode_www_form(qs) if qs.size > 0
|
162
|
+
end
|
163
|
+
|
164
|
+
case media_type
|
165
|
+
when 'audio'
|
166
|
+
cfg['autoplay'] = qs['autoplay'] || data[:autoplay] || cfg['autoplay']
|
167
|
+
cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
|
168
|
+
cfg['style'] += ';display: none;' if qs['hidden']
|
169
|
+
content = handle_audio(content, { target: match_data[0], cfg: cfg })
|
170
|
+
when 'iframe'
|
171
|
+
cfg['title'] = title
|
172
|
+
cfg['width'] = qs['width'] || data[:width] || cfg['width']
|
173
|
+
cfg['height'] = qs['height'] || data[:height] || cfg['height']
|
174
|
+
cfg['frameborder'] = qs['frameborder'] || cfg['frameborder']
|
175
|
+
cfg['allow'] ||= cfg['allow']
|
176
|
+
content = handle_iframe(content, { target: match_data[0], cfg: cfg })
|
177
|
+
end
|
178
|
+
self.handled = true
|
179
|
+
end
|
180
|
+
content
|
181
|
+
end
|
182
|
+
|
183
|
+
def handle_audio(content, data)
|
184
|
+
cfg = data[:cfg]
|
185
|
+
html = "<audio"\
|
186
|
+
" id=\"#{cfg['id']}\""\
|
187
|
+
" class=\"#{cfg['class']}\""\
|
188
|
+
" #{cfg['autoplay'] ? 'autoplay' : ''}"\
|
189
|
+
" #{cfg['loop'] ? 'loop' : ''}"\
|
190
|
+
" src=\"#{cfg['src']}\""\
|
191
|
+
" style=\"#{cfg['style']}\""\
|
192
|
+
" controls>" \
|
193
|
+
"<p> Your browser doesn't support HTML5 audio."\
|
194
|
+
" Here is a <a href=\"#{cfg['src']}\">link to download the audio</a>"\
|
195
|
+
"instead. </p>"\
|
196
|
+
"</audio>"
|
197
|
+
content.gsub(data[:target], html)
|
198
|
+
end
|
199
|
+
|
200
|
+
def handle_iframe(content, data)
|
201
|
+
cfg = data[:cfg]
|
202
|
+
html = "<iframe"\
|
203
|
+
" id=\"#{cfg['id']}\""\
|
204
|
+
" class=\"#{cfg['class']}\""\
|
205
|
+
" src=\"#{cfg['src']}\""\
|
206
|
+
" title=\"#{cfg['title']}\""\
|
207
|
+
" width=\"#{cfg['width']}\""\
|
208
|
+
" height=\"#{cfg['height']}\""\
|
209
|
+
" style=\"#{cfg['style']}\""\
|
210
|
+
" allow=\"#{cfg['allow']}\""\
|
211
|
+
" frameborder=\"#{cfg['frameborder']}\""\
|
212
|
+
" allowfullscreen>"\
|
213
|
+
"</iframe>"
|
214
|
+
content.gsub(data[:target], html)
|
215
|
+
end
|
216
|
+
|
217
|
+
def get_id_from_html(url, pattern)
|
218
|
+
id = ''
|
219
|
+
begin
|
220
|
+
url = 'https:' + url if url.start_with? '//'
|
221
|
+
res = Net::HTTP.get_response URI(url)
|
222
|
+
raise res.body unless res.is_a?(Net::HTTPSuccess)
|
223
|
+
res.body.match pattern do |match_data|
|
224
|
+
id = match_data[0]
|
225
|
+
break
|
226
|
+
end
|
227
|
+
rescue StandardError => msg
|
228
|
+
data = url
|
229
|
+
logger.log msg
|
230
|
+
end
|
231
|
+
id
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffreytse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -140,11 +140,11 @@ files:
|
|
140
140
|
- lib/jekyll-spaceship/processors/element-processor.rb
|
141
141
|
- lib/jekyll-spaceship/processors/emoji-processor.rb
|
142
142
|
- lib/jekyll-spaceship/processors/mathjax-processor.rb
|
143
|
+
- lib/jekyll-spaceship/processors/media-processor.rb
|
143
144
|
- lib/jekyll-spaceship/processors/mermaid-processor.rb
|
144
145
|
- lib/jekyll-spaceship/processors/plantuml-processor.rb
|
145
146
|
- lib/jekyll-spaceship/processors/polyfill-processor.rb
|
146
147
|
- lib/jekyll-spaceship/processors/table-processor.rb
|
147
|
-
- lib/jekyll-spaceship/processors/video-processor.rb
|
148
148
|
- lib/jekyll-spaceship/utils/.keep
|
149
149
|
- lib/jekyll-spaceship/version.rb
|
150
150
|
- logos/jekyll-spaceship-logo.png
|
@@ -173,5 +173,6 @@ rubygems_version: 3.0.8
|
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
|
176
|
-
mermaid, emoji, video, youtube, vimeo, dailymotion,
|
176
|
+
mermaid, emoji, video, audio, youtube, vimeo, dailymotion, spotify, soundcloud,
|
177
|
+
etc.
|
177
178
|
test_files: []
|
@@ -1,139 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
module Jekyll::Spaceship
|
6
|
-
class VideoProcessor < Processor
|
7
|
-
def self.config
|
8
|
-
{
|
9
|
-
'default' => {
|
10
|
-
'id' => 'video-{id}',
|
11
|
-
'class' => 'video',
|
12
|
-
'width' => '100%',
|
13
|
-
'height' => 350,
|
14
|
-
'border' => 0,
|
15
|
-
'style' => 'max-width: 600px',
|
16
|
-
'allow' => 'encrypted-media; picture-in-picture',
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def on_handle_markdown(content)
|
22
|
-
content = handle_normal_video(content)
|
23
|
-
content = handle_youtube(content)
|
24
|
-
content = handle_vimeo(content)
|
25
|
-
content = handle_dailymotion(content)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Examples:
|
29
|
-
# ![video](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
|
30
|
-
# ![video](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
|
31
|
-
# ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
|
32
|
-
def handle_normal_video(content)
|
33
|
-
handle_video(content, {
|
34
|
-
host: '(https?:)?\\/\\/.*\\/',
|
35
|
-
id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))',
|
36
|
-
})
|
37
|
-
end
|
38
|
-
|
39
|
-
# Examples:
|
40
|
-
# ![youtube](https://www.youtube.com/watch?v=XA2WjJbmmoM "title")
|
41
|
-
# ![youtube](http://www.youtube.com/embed/w-m_yZCLF5Q)
|
42
|
-
# ![youtube](//youtu.be/mEP3YXaSww8?height=100%&width=400)
|
43
|
-
def handle_youtube(content)
|
44
|
-
handle_video(content, {
|
45
|
-
host: '(https?:)?\\/\\/.*youtu.*',
|
46
|
-
id: '(?<=\\?v\\=|embed\\/|\\.be\\/)([a-zA-Z0-9\\_\\-]+)',
|
47
|
-
iframe_url: "https://www.youtube.com/embed/"
|
48
|
-
})
|
49
|
-
end
|
50
|
-
|
51
|
-
# Examples:
|
52
|
-
# ![vimeo](https://vimeo.com/263856289)
|
53
|
-
# ![vimeo](https://vimeo.com/263856289?height=100%&width=400)
|
54
|
-
def handle_vimeo(content)
|
55
|
-
handle_video(content, {
|
56
|
-
host: '(https?:)?\\/\\/vimeo\\.com\\/',
|
57
|
-
id: '([0-9]+)',
|
58
|
-
iframe_url: "https://player.vimeo.com/video/"
|
59
|
-
})
|
60
|
-
end
|
61
|
-
|
62
|
-
# Examples:
|
63
|
-
# ![dailymotion](https://www.dailymotion.com/video/x7tgcev)
|
64
|
-
# ![dailymotion](https://dai.ly/x7tgcev?height=100%&width=400)
|
65
|
-
def handle_dailymotion(content)
|
66
|
-
handle_video(content, {
|
67
|
-
host: '(https?:)?\\/\\/.*dai.?ly.*',
|
68
|
-
id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)',
|
69
|
-
iframe_url: "https://www.dailymotion.com/embed/video/"
|
70
|
-
})
|
71
|
-
end
|
72
|
-
|
73
|
-
def handle_video(content, data)
|
74
|
-
host = data[:host]
|
75
|
-
return content if content.sub(/#{host}/, '').nil?
|
76
|
-
|
77
|
-
iframe_url = data[:iframe_url]
|
78
|
-
id = data[:id]
|
79
|
-
url = "(#{host}#{id}\\S*)"
|
80
|
-
title = '("(.*)".*){0,1}'
|
81
|
-
|
82
|
-
# pre-handle reference-style links
|
83
|
-
regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/
|
84
|
-
content.scan regex do |match_data|
|
85
|
-
match = match_data[0]
|
86
|
-
ref_name = match_data[1]
|
87
|
-
ref_value = match_data[2]
|
88
|
-
content = content.gsub(match, '')
|
89
|
-
.gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/,
|
90
|
-
"![\1](#{ref_value})")
|
91
|
-
end
|
92
|
-
|
93
|
-
# handle inline-style links
|
94
|
-
regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/
|
95
|
-
content.scan regex do |match_data|
|
96
|
-
url = match_data[2]
|
97
|
-
id = match_data[4]
|
98
|
-
title = match_data[6]
|
99
|
-
qs = url.match(/(?<=\?)(\S*?)$/)
|
100
|
-
qs = Hash[URI.decode_www_form(qs.to_s)].reject do |k, v|
|
101
|
-
next true if v == id or v == ''
|
102
|
-
end
|
103
|
-
|
104
|
-
default = self.config['default']
|
105
|
-
css_id = qs['id'] || default['id']
|
106
|
-
css_class = qs['class'] || default['class']
|
107
|
-
width = qs['width'] || data[:width] || default['width']
|
108
|
-
height = qs['height'] || data[:height] || default['height']
|
109
|
-
frameborder = qs['frameborder'] || default['border']
|
110
|
-
style = qs['style'] || default['style']
|
111
|
-
allow = qs['allow'] || default['allow']
|
112
|
-
|
113
|
-
css_id = css_id.gsub('{id}', id)
|
114
|
-
css_class = css_class.gsub('{id}', id)
|
115
|
-
|
116
|
-
url = URI(iframe_url ? "#{iframe_url}#{id}" : url).tap do |v|
|
117
|
-
v.query = URI.encode_www_form(qs) if qs.size > 0
|
118
|
-
end
|
119
|
-
|
120
|
-
html = "<iframe"\
|
121
|
-
" id=\"#{css_id}\""\
|
122
|
-
" class=\"#{css_class}\""\
|
123
|
-
" src=\"#{url}\""\
|
124
|
-
" title=\"#{title}\""\
|
125
|
-
" width=\"#{width}\""\
|
126
|
-
" height=\"#{height}\""\
|
127
|
-
" style=\"#{style}\""\
|
128
|
-
" allow=\"#{allow}\""\
|
129
|
-
" frameborder=\"#{frameborder}\""\
|
130
|
-
" allowfullscreen>" \
|
131
|
-
"</iframe>"
|
132
|
-
|
133
|
-
content = content.gsub(match_data[0], html)
|
134
|
-
self.handled = true
|
135
|
-
end
|
136
|
-
content
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|