Created
December 9, 2012 13:32
-
-
Save futoase/4244901 to your computer and use it in GitHub Desktop.
Octopress Nicovideo plugin
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
# -*- coding:utf-8 -*- | |
require 'open-uri' | |
require 'rexml/document' | |
API_BASE = 'http://ext.nicovideo.jp/api/getthumbinfo/' | |
module Jekyll | |
class Nicovideo < Liquid::Tag | |
def initialize(name, id, tokens) | |
super | |
@id = id | |
end | |
def render(context) | |
@title = REXML::XPath.first( | |
REXML::Document.new(open(API_BASE + @id).read), '//title' | |
).text | |
%(<div style="margin-left: auto; margin-right: auto; width: 500px;"><script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/#{@id}"></script><noscript><a href="http://www.nicovideo.jp/watch/#{@id}">#{@title}</a></noscript></div>) | |
end | |
end | |
end | |
Liquid::Template.register_tag('nicovideo', Jekyll::Nicovideo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment