summaryrefslogtreecommitdiffstats
path: root/blog/_plugins/video_embed.rb
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2016-10-17 12:16:02 +0200
committerHarald Eilertsen <haraldei@anduin.net>2016-10-17 12:16:02 +0200
commit2d779fce509e2c4718247db398f4c8e5fab09c8c (patch)
treee59918f503cd8d415e422aa0eb270c451ca840b2 /blog/_plugins/video_embed.rb
parent78d60b03e370439bd1c4d5e107ee71d160f5cb60 (diff)
downloadnorsk-urskog-main-2d779fce509e2c4718247db398f4c8e5fab09c8c.tar.gz
norsk-urskog-main-2d779fce509e2c4718247db398f4c8e5fab09c8c.tar.bz2
norsk-urskog-main-2d779fce509e2c4718247db398f4c8e5fab09c8c.zip
Add video_embed plugin.
Diffstat (limited to 'blog/_plugins/video_embed.rb')
-rw-r--r--blog/_plugins/video_embed.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/blog/_plugins/video_embed.rb b/blog/_plugins/video_embed.rb
new file mode 100644
index 0000000..cf4d04a
--- /dev/null
+++ b/blog/_plugins/video_embed.rb
@@ -0,0 +1,42 @@
+# Fetched from https://github.com/eug/jekyll-video-embed
+# MIT-licence: https://raw.githubusercontent.com/eug/jekyll-video-embed/master/LICENSE
+
+module Jekyll
+ class VideoEmbed < Liquid::Tag
+
+ Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
+
+ Hosts = {
+ "ted" => ->(id) { "https://embed-ssl.ted.com/talks/#{id}.html" },
+ "ustream" => ->(id) { "http://ustream.tv/embed/#{id}" },
+ "vimeo" => ->(id) { "https://player.vimeo.com/video/#{id}" },
+ "youtube" => ->(id) { "http://youtube.com/embed/#{id}" }
+ }
+
+ def initialize(tag_name, markup, tokens)
+ super
+
+ if markup =~ Syntax then
+ @host = Hosts[tag_name]
+ @id = $1
+
+ if $2.nil? then
+ @width = 590
+ @height = 360
+ else
+ @width = $2.to_i
+ @height = $3.to_i
+ end
+ else
+ raise "No video ID provided in the \"#{tag_name}\" tag"
+ end
+ end
+
+ def render(context)
+ "<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"#{@host.call(@id)}\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"
+ end
+
+ Hosts.each_key { |key| Liquid::Template.register_tag key, self }
+
+ end
+end