From 1f2375a53d1a588edd3294234a6c04f5c2dd197d Mon Sep 17 00:00:00 2001 From: Jonas Rosland Date: Fri, 31 Jan 2020 15:20:19 -0500 Subject: [PATCH] Add YouTube plugin for the site (#2236) Signed-off-by: Jonas Rosland --- site/_plugins/youtube.rb | 123 +++++++++++++++++++++++++++++++++++++++ site/resources.md | 20 ++++--- 2 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 site/_plugins/youtube.rb diff --git a/site/_plugins/youtube.rb b/site/_plugins/youtube.rb new file mode 100644 index 000000000..e322446aa --- /dev/null +++ b/site/_plugins/youtube.rb @@ -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 + "" + 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) diff --git a/site/resources.md b/site/resources.md index ee1c1386e..a1b60eb55 100644 --- a/site/resources.md +++ b/site/resources.md @@ -8,7 +8,7 @@ Here you will find external resources about Velero, such as videos, podcasts, an ## All community meetings - +{% youtube videoseries?list=PL7bmigfV0EqQRysvqvqOtRNk4L5S7uqwM %} ## Podcast shows @@ -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: - + {% youtube JyzgS-KKuoo %} +
* Kubernetes Back Up, Restore and Migration with Velero - A NewStack interview, with guests: Carlisia Campos, Tom Spoonemore, and Efri Nattel-Shayo: - + {% youtube 71NoY5CIcQ8 %} +
* How to migrate applications between Kubernetes clusters using Velero: - + {% youtube IZlwKMoqBqE %} +
* TGIK 080: Velero 1.0: - + {% youtube tj5Ey2bHsfM %} +
* Watch our recent webinar on backup and migration strategies: - + {% youtube csrSPt3HFtg %} +
* Velero demo by Just me and Opensource - [ Kube 45 ] Velero - Backup & Restore Kubernetes Cluster: - - + {% youtube C9hzrexaIDA %} ## Blog posts