1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,47 @@ |
0 |
+# Title: Simple Video tag for Jekyll |
|
1 |
+# Author: Brandon Mathis http://brandonmathis.com |
|
2 |
+# Description: Easily output MPEG4 HTML5 video with a flash backup. |
|
3 |
+# |
|
4 |
+# Syntax {% video url/to/video [width height] [url/to/poster] %} |
|
5 |
+# |
|
6 |
+# Example: |
|
7 |
+# {% video http://site.com/video.mp4 720 480 http://site.com/poster-frame.jpg %} |
|
8 |
+# |
|
9 |
+# Output: |
|
10 |
+# <video width='720' height='480' preload='none' controls poster='http://site.com/poster-frame.jpg'> |
|
11 |
+# <source src='http://site.com/video.mp4' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'/> |
|
12 |
+# </video> |
|
13 |
+# |
|
14 |
+ |
|
15 |
+module Jekyll |
|
16 |
+ |
|
17 |
+ class VideoTag < Liquid::Tag |
|
18 |
+ @video = nil |
|
19 |
+ @poster = '' |
|
20 |
+ @height = '' |
|
21 |
+ @width = '' |
|
22 |
+ |
|
23 |
+ def initialize(tag_name, markup, tokens) |
|
24 |
+ if markup =~ /((https?:\/\/|\/)(\S+))(\s+(\d+)\s(\d+))?(\s+(https?:\/\/|\/)(\S+))?/i |
|
25 |
+ @video = $1 |
|
26 |
+ @width = $5 |
|
27 |
+ @height = $6 |
|
28 |
+ @poster = $7 |
|
29 |
+ end |
|
30 |
+ super |
|
31 |
+ end |
|
32 |
+ |
|
33 |
+ def render(context) |
|
34 |
+ output = super |
|
35 |
+ if @video |
|
36 |
+ video = "<video width='#{@width}' height='#{@height}' preload='none' controls poster='#{@poster}'>" |
|
37 |
+ video += "<source src='#{@video}' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'/></video>" |
|
38 |
+ else |
|
39 |
+ "Error processing input, expected syntax: {% video url/to/video [width height] [url/to/poster] %}" |
|
40 |
+ end |
|
41 |
+ end |
|
42 |
+ end |
|
43 |
+end |
|
44 |
+ |
|
45 |
+Liquid::Template.register_tag('video', Jekyll::VideoTag) |
|
46 |
+ |