-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·51 lines (44 loc) · 3.51 KB
/
index.js
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
'use strict';
hexo.extend.tag.register('instagram', function(args, content){
var config = hexo.config.tagInstagram || {};
config.width = config.width || "100%";
config.is_captioned = config.captioned || true;
var postId = "";
var returnHTML = "";
// advanced argument "key:value"
for (var i in args) {
var arg = args[i];
if(arg.startsWith('id:')) {
postId = arg.slice(3).trim();
}else if(arg.startsWith('url:')) {
var postURL = arg.slice(4).trim();
postId = postURL.match(/https\:\/\/www\.instagram\.com\/p\/([0-9a-zA-Z-_]+)/)[1]
}else if(arg.startsWith('width:')) {
config.width = arg.slice(6).trim();
}else if(arg.startsWith('captioned:')) {
config.is_captioned = arg.slice(10).trim()=='true'?true:false;
}
}
// common argument "value"
for (var i in args) {
var arg = args[i];
if(["true", "false"].indexOf(arg)>-1) {
config.is_captioned = ["true", "false"].indexOf(arg)==0? true : false;
}else if(postId.length==0 && arg.match(/https\:\/\/www\.instagram\.com\/p\/[0-9a-zA-Z-_]+/)) {
postId = arg.match(/https\:\/\/www\.instagram\.com\/p\/([0-9a-zA-Z-_]+)/)[1];
}else if(postId.length==0 && arg.length>4 && arg.match(/([0-9a-zA-Z-_]+)/)) {
postId = arg.match(/([0-9a-zA-Z-_]+)/)[1];
}else if(arg.length < 4 && arg.match(/([0-9]+\%)/)) {
config.width = arg.match(/([0-9]+\%)/)[1];
}
}
if(postId.length==0) return returnHTML;
// generate html
if(postId != ""){
returnHTML = '<div class="instagram-wrapper"><blockquote class="instagram-media"' + (config.is_captioned ? ' data-instgrm-captioned' : '') + ' data-instgrm-version="7" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px auto; padding:0; width:99.375%; width:-webkit-calc(' + config.width + '- 2px); width:calc(' + config.width + ' - 2px);"><div style="padding:8px;"> <div style=" background:#F8F8F8; line-height:0; margin-top:40px; padding:50.0% 0; text-align:center; width:100%;"> <div style=" background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAMUExURczMzPf399fX1+bm5mzY9AMAAADiSURBVDjLvZXbEsMgCES5/P8/t9FuRVCRmU73JWlzosgSIIZURCjo/ad+EQJJB4Hv8BFt+IDpQoCx1wjOSBFhh2XssxEIYn3ulI/6MNReE07UIWJEv8UEOWDS88LY97kqyTliJKKtuYBbruAyVh5wOHiXmpi5we58Ek028czwyuQdLKPG1Bkb4NnM+VeAnfHqn1k4+GPT6uGQcvu2h2OVuIf/gWUFyy8OWEpdyZSa3aVCqpVoVvzZZ2VTnn2wU8qzVjDDetO90GSy9mVLqtgYSy231MxrY6I2gGqjrTY0L8fxCxfCBbhWrsYYAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-22px; width:44px;"></div></div><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/' + postId + '/" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank"></a></p></div></blockquote></div><script async defer src="//platform.instagram.com/en_US/embeds.js"></script>';
}
return returnHTML;
},{
async: true,
ends: false
});