Skip to content

Instantly share code, notes, and snippets.

@Yexiaoxing
Last active June 26, 2018 03:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yexiaoxing/5891929 to your computer and use it in GitHub Desktop.
Save Yexiaoxing/5891929 to your computer and use it in GitHub Desktop.
Plugin for Jekyll to insert videos from Youku or Tudou.

这是一个用于Jekyll的youku、tudou嵌入插件。

This is a plugin meant for Jekyll.

用例:

Example use:

将youku.rb和/或tudou.rb文件拷贝至_plugins目录下,然后在文章中输入以下代码即可嵌入。

Easily embed a YouTube video. Just drop these files in your `_plugins directory.

{% youku XNTc2ODk1NjI0 %}
{% tudou XNTc2ODk1NjI0 %}

你还可以定义播放器的宽度和高度。如果你不提供,将使用默认值560 x 420。

You can also specify a height and width. If you do not, it defaults to 560 x 420.

{% youku XNTc2ODk1NjI0 500 400 %}
{% tudou XNTc2ODk1NjI0 500 400 %}

基于Generate YouTube Embed (tag) by joelverhagen制作。

Based on Generate YouTube Embed (tag) by joelverhagen

class TuDou < Liquid::Tag
Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
def initialize(tagName, markup, tokens)
super
if markup =~ Syntax then
@id = $1
if $2.nil? then
@width = 560
@height = 420
else
@width = $2.to_i
@height = $3.to_i
end
else
raise "在\"TuDou\"标签中未提供视频ID或提供的ID不合法。 Illgeal ID presented."
end
end
def render(context)
# "<iframe height=498 width=510 src="http://player.youku.com/embed/XNTc2ODk1NjI0" frameborder=0 allowfullscreen></iframe>"
"<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"http://www.tudou.com/programs/view/html5embed.action?code=#{@id}\" frameborder=0 allowfullscreen></iframe>"
end
Liquid::Template.register_tag "tudou", self
end
class YouKu < Liquid::Tag
Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
def initialize(tagName, markup, tokens)
super
if markup =~ Syntax then
@id = $1
if $2.nil? then
@width = 560
@height = 420
else
@width = $2.to_i
@height = $3.to_i
end
else
raise "在\"Youku\"标签中未提供视频ID或提供的ID不合法。 Illgeal ID presented."
end
end
def render(context)
# "<iframe height=498 width=510 src="http://player.youku.com/embed/XNTc2ODk1NjI0" frameborder=0 allowfullscreen></iframe>"
"<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"http://player.youku.com/embed/#{@id}\" frameborder=0 allowfullscreen></iframe>"
end
Liquid::Template.register_tag "youku", self
end
@guodidi
Copy link

guodidi commented Mar 27, 2016

您好,我是在 Jekyll Plugins看到的这个插件。目前,我还没有使用这个插件,但是由于这个插件是基于 Generate YouTube Embed (tag) by joelverhagen 制作的,但是joelverhagen的正则表达式的写法在我看来是有瑕疵的,你可以上 a Ruby regular expression editor 测试一下。

当我输入joelverhagen的表达式即^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?的时候,结果是有四个变量而非三个变量,我想也许是因为整个正则表达式中有四个()的原因。所以我尝试修改了Syntax为^\s*([^\s]+)\s*(\d+)?\s*(\d+)?\s*?,这时候的输出可以非常好的匹配程序的其他地方。

所以,如果您有空的,可以再次检查下这个正则表达式,希望它可以为更多人服务。

欢迎您的再次指教,谢谢

@awong1900
Copy link

发下https网站下插入不能显示啊,应该与你的插件没关系。只是吐槽一下youku不支持https网址。

@Yexiaoxing
Copy link
Author

@guodidi 非常感谢你的意见。也是好久没碰这个插件了,修改了一下 regex。
@awong1900 能提供一下测试的链接吗?

@naffan2014
Copy link

@Yexiaoxing Liquid syntax error (line 4): Unknown tag 'youku'。 一切按照步骤来的

@MorvanZhou
Copy link

MorvanZhou commented Nov 16, 2016

@awong1900 对我也在纠结 https 的事情, 网上找了一圈也没能找到合适的解决办法. 优酷的 embedded 视频不能在 https 协议的网页播放

@hax
Copy link

hax commented Dec 21, 2016

貌似把 http://player.youku.com 换成 https://players.youku.com 就可以了。 players 那个域名是支持 https 的。

更新:刚才联系了优酷的同学,他们表示正在升级,马上就会全面支持https啦。

@2017noobman
Copy link

我测试结果是要求属性都用双引号包含

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment