-
Notifications
You must be signed in to change notification settings - Fork 0
/
instagram.rb
41 lines (34 loc) · 1013 Bytes
/
instagram.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
# A liquid tag for Jekyll to embed Instagram photos.
# OKUMURA Takahiro <hfm.garden@gmail.com>
#
# Usage:
# {% instagram hash %}
# Params:
# hash: When a short link has instagram.com/p/abcdefghij, a hash is abcdefghij
# access_token:
# This file includes only your access_token for instagram.
# see http://instagram.com/developer/authentication
require 'instagram'
module Jekyll
class InstagramEmbedTag < Liquid::Tag
def initialize(tag_name, hash, token)
super
@hash = hash.strip
access_token_file = File.expand_path('.instagram/access_token', File.dirname(__FILE__))
@access_token = File.open(access_token_file).gets.strip
end
def render(context)
embed_code
end
def embed_code
oembed.html
end
def oembed
client.oembed("instagram.com/p/#{@hash}")
end
def client
Instagram.client(access_token: @access_token)
end
end
end
Liquid::Template.register_tag("instagram", Jekyll::InstagramEmbedTag)