Skip to content

Instantly share code, notes, and snippets.

@Yexiaoxing
Last active June 26, 2018 03:49
Show Gist options
  • 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
@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