-
Notifications
You must be signed in to change notification settings - Fork 2
/
tweet.rb
57 lines (42 loc) · 879 Bytes
/
tweet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Tweet Liquid Tag
#
# Example:
# {% tweet 464180168303456256 %}
#
require 'net/http'
require 'json'
module Jekyll
class TweetTag < Liquid::Tag
#
#
#
def render(context)
if tag_contents = determine_arguments(@markup.strip)
tweet_id = tag_contents #
tweet_script_tag(tweet_id)
else
raise ArgumentError.new <<-eos
Syntax error
eos
end
end
private
#
#
#
def determine_arguments(input)
return input
end
#
#
#
def tweet_script_tag(tweet_id)
result = Net::HTTP.get(URI.parse("https://api.twitter.com/1/statuses/oembed.json?id=#{tweet_id}"))
json = JSON.parser.new(result)
hash = json.parse()
parsed = hash['html']
return parsed
end
end
end
Liquid::Template.register_tag('tweet', Jekyll::TweetTag)