Skip to content

Commit

Permalink
Add YouTube plugin for the site (#2236)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Rosland <jrosland@vmware.com>
  • Loading branch information
jonasrosland authored Jan 31, 2020
1 parent 37011ee commit 1f2375a
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 8 deletions.
123 changes: 123 additions & 0 deletions site/_plugins/youtube.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Title: YouTube plugin for Jekyll
# Description: Liquid tag to generate a YouTube embed.
# Authors:
# - Joey Hoer (@joeyhoer | https://joeyhoer.com)
#
# Link: https://developers.google.com/youtube/player_parameters#Parameters
#
# Syntax: {% youtube [video_id] [width] [height] [query_param:value]... %}
#
# Examples:
# {% youtube dQw4w9WgXcQ %}
# {% youtube dQw4w9WgXcQ 600 rel:0 modestbranding:1 %}
#

module Jekyll
class YouTube < Liquid::Tag

## Constants

@@ATTRIBUTES = %w(
autoplay
cc_load_policy
color
controls
disablekb
enablejsapi
end
fs
hl
iv_load_policy
list
listType
loop
modestbranding
origin
playlist
playsinline
rel
showinfo
start
widget_referrer
)

@ytid = nil
@width = ''
@height = ''

def initialize(tag_name, markup, tokens)
@content=markup

@config = {}

# Override configuration with values defined within _config.yml
if Jekyll.configuration({}).has_key?('youtube')
config = Jekyll.configuration({})['youtube']
override_config(config)
end

params = markup.split

if params.shift =~ /(?:(?:https?:\/\/)?(?:www.)?(?:youtube.com\/(?:embed\/|watch\?v=)|youtu.be\/)?(\S+)(?:\?rel=\d)?)/i
@video_id = $1
end

@width = (params[0].to_i > 0) ? params.shift.to_i : 560
@height = (params[0].to_i > 0) ? params.shift.to_i : (@width / 16.0 * 9).ceil

if params.size > 0
# Override configuration with parameters defined within Liquid tag
config = {} # Reset local config
params.each do |param|
param = param.gsub /\s+/, '' # Remove whitespaces
key, value = param.split(':',2) # Split first occurrence of ':' only
config["#{key}"] = value
end
override_config(config)
end

super
end

def override_config(config)
config.each{ |key,value| @config[key] = value }
end

def render(context)
ouptut = super

if !@video_id
@video_id = "#{context[@content.strip]}"
end

if @video_id
template_path = File.join(Dir.pwd, "_includes", "youtube.html")
if File.exist?(template_path)
site = context.registers[:site]

partial = File.read(template_path)
template = Liquid::Template.parse(partial)

template.render!(({"video_id" => @video_id, "width" => @width, "height" => @height, "query_string" => render_query_string()}).merge(site.site_payload))
else
"<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"https://www.youtube.com/embed/#{@video_id}#{render_query_string()}\" frameborder=\"0\" allowfullscreen></iframe>"
end
else
puts "YouTube Embed: Error processing input, expected syntax {% youtube video_id [width] [height] [data-attr:value] %}"
end
end

def render_query_string
result = []
@config.each do |key,value|
if @@ATTRIBUTES.include?(key.to_s)
result << "#{key}=#{value}"
end
end
return (!(result.empty?) ? '?' : '') + result.join('&')
end

end
end

Liquid::Template.register_tag('youtube', Jekyll::YouTube)
20 changes: 12 additions & 8 deletions site/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Here you will find external resources about Velero, such as videos, podcasts, an

## All community meetings

<iframe title="Velero Community Meetings/Open Discussions" width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PL7bmigfV0EqQRysvqvqOtRNk4L5S7uqwM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% youtube videoseries?list=PL7bmigfV0EqQRysvqvqOtRNk4L5S7uqwM %}

## Podcast shows

Expand All @@ -20,33 +20,37 @@ Here you will find external resources about Velero, such as videos, podcasts, an

* Kubecon NA 2019 - How to Backup and Restore Your Kubernetes Cluster - Annette Clewett & Dylan Murray, Red Hat:

<iframe title="How to Backup and Restore Your Kubernetes Cluster - Annette Clewett & Dylan Murray, Red Hat" width="560" height="315" src="https://www.youtube.com/embed/JyzgS-KKuoo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% youtube JyzgS-KKuoo %}

</br>

* Kubernetes Back Up, Restore and Migration with Velero - A NewStack interview, with guests: Carlisia Campos, Tom Spoonemore, and Efri Nattel-Shayo:

<iframe title="Kubernetes Back Up, Restore and Migration with Velero - NewStack, with guests: Carlisia Campos, Tom Spoonemore, and Efri Nattel-Shayo" width="560" height="315" src="https://www.youtube.com/embed/71NoY5CIcQ8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% youtube 71NoY5CIcQ8 %}

</br>

* How to migrate applications between Kubernetes clusters using Velero:

<iframe title="How to migrate applications between Kubernetes clusters using Velero" width="560" height="315" src="https://www.youtube.com/embed/IZlwKMoqBqE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% youtube IZlwKMoqBqE %}

</br>

* TGIK 080: Velero 1.0:

<iframe title="TGIK 080: Velero 1.0" width="560" height="315" src="https://www.youtube.com/embed/tj5Ey2bHsfM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% youtube tj5Ey2bHsfM %}

</br>

* Watch our recent webinar on backup and migration strategies:

<iframe title="Kubernetes Backup and Migration Strategies using Project Velero" width="560" height="315" src="https://www.youtube.com/embed/csrSPt3HFtg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% youtube csrSPt3HFtg %}

</br>

* Velero demo by Just me and Opensource - [ Kube 45 ] Velero - Backup & Restore Kubernetes Cluster:

<iframe title="[ Kube 45 ] Velero - Backup & Restore Kubernetes Cluster" width="560" height="315" src="https://www.youtube.com/embed/C9hzrexaIDA" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

{% youtube C9hzrexaIDA %}

## Blog posts

Expand Down

0 comments on commit 1f2375a

Please sign in to comment.