... | ... |
@@ -22,22 +22,31 @@ module Jekyll |
22 | 22 |
@width = '' |
23 | 23 |
|
24 | 24 |
def initialize(tag_name, markup, tokens) |
25 |
- if markup =~ /((https?:\/\/|\/)(\S+))(\s+(\d+)\s(\d+))?(\s+(https?:\/\/|\/)(\S+))?/i |
|
26 |
- @video = $1 |
|
27 |
- @width = $5 |
|
28 |
- @height = $6 |
|
29 |
- @poster = $7 |
|
25 |
+ if markup =~ /(https?:\S+)(\s+(https?:\S+))?(\s+(https?:\S+))?(\s+(\d+)\s(\d+))?(\s+(https?:\S+))?/i |
|
26 |
+ @video = [$1, $3, $5].compact |
|
27 |
+ @width = $7 |
|
28 |
+ @height = $8 |
|
29 |
+ @poster = $10 |
|
30 | 30 |
end |
31 | 31 |
super |
32 | 32 |
end |
33 | 33 |
|
34 | 34 |
def render(context) |
35 | 35 |
output = super |
36 |
- if @video |
|
36 |
+ type = { |
|
37 |
+ 'mp4' => "type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'", |
|
38 |
+ 'ogv' => "type='video/ogg; codecs=theora, vorbis'", |
|
39 |
+ 'webm' => "type='video/webm; codecs=vp8, vorbis'" |
|
40 |
+ } |
|
41 |
+ if @video.size > 0 |
|
37 | 42 |
video = "<video width='#{@width}' height='#{@height}' preload='none' controls poster='#{@poster}'>" |
38 |
- video += "<source src='#{@video}' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'/></video>" |
|
43 |
+ @video.each do |v| |
|
44 |
+ t = v.match(/([^\.]+)$/)[1] |
|
45 |
+ video += "<source src='#{v}' #{type[t]}>" |
|
46 |
+ end |
|
47 |
+ video += "</video>" |
|
39 | 48 |
else |
40 |
- "Error processing input, expected syntax: {% video url/to/video [width height] [url/to/poster] %}" |
|
49 |
+ "Error processing input, expected syntax: {% video url/to/video [url/to/video] [url/to/video] [width height] [url/to/poster] %}" |
|
41 | 50 |
end |
42 | 51 |
end |
43 | 52 |
end |