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
@2017noobman
Copy link

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

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