Last active
August 29, 2015 13:56
-
-
Save zhantongz/9317303 to your computer and use it in GitHub Desktop.
Simple YouTube embedment with alternate source for Jekyll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Simple YouTube embedment with alternate source for Jekyll | |
# Author: Zhantong Zhang http://zhantong.org | |
# Description: Easily output embeded YouTube video with a backup inside GFW (Tudou). | |
# Use: Put this file in plugins/ and youtubeCN.js in source/javascripts | |
# | |
# Syntax {% ytb youtube/id [width height] [autopage] [tudou/id] %} | |
module Jekyll | |
class YtbGFW < Liquid::Tag | |
@width = '' | |
@height = '' | |
@autoplay = 0 | |
@id = '' | |
@td_id = '' | |
def initialize(tag_name, markup, tokens) | |
super | |
parameters = markup.split(" ") | |
@id = parameters.first | |
@td_id = parameters.last | |
@width = parameters[1] | |
@height = parameters[2] | |
@config = | |
@root_url = Jekyll.configuration({})['url'] | |
if parameters[1] =~ /^\d+$/ | |
if parameters[2] =~ /^\d+$|^\d+px$|^\d+%$/ | |
@autoplay = parameters[3] | |
else | |
@autoplay = parameters[1] | |
end | |
end | |
end | |
def render(context) | |
if @td_id != @id | |
%(<div class="embed-video-container" width="#{@width}" id="yt"><iframe id="ytplayer" type="text/html" width="#{@width}" src="http://www.youtube.com/embed/#{@id}?autoplay=#{@autoplay}&origin=http://blog.zhantong.org" frameborder="0"></iframe></div><div class="embed-video-container flash-video" id="td"><iframe id="tdplayer" src="http://www.tudou.com/programs/view/html5embed.action?code=#{@td_id}&resourceId=356292153_06_05_99" allowtransparency="true" scrolling="no" border="0" frameborder="0" style="width:#{@width};"></iframe></div><script src="#{@root_url}/javascripts/youtubeCN.js" type="text/javascript"></script>) | |
else | |
%(<div class="embed-video-container" id="yt" width="#{@width}><iframe id="ytplayer" type="text/html" width="#{@width}" src="http://www.youtube.com/embed/#{@id}?autoplay=#{@autoplay}&origin=http://blog.zhantong.org" frameborder="0"></iframe></div><script src="#{@root_url}/javascripts/youtubeCN.js" type="text/javascript"></script>) | |
end | |
end | |
end | |
end | |
Liquid::Template.register_tag('ytb', Jekyll::YtbGFW) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put it in source/javascripts/ directory | |
var icon = "http://s.ytimg.com/yts/img/favicon-vfldLzJxy.ico"; | |
var locationWall = (! $('<img src="'+ icon +'">').load()); // false if out of Mainland; true otherwise | |
var plid="td"; // remove tudou if outside of Mainland | |
if(locationWall) | |
{ | |
plid="yt" // remove youtube if inside of Mainland | |
} | |
var player=document.getElementById(plid); | |
player.parentNode.removeChild(player); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment