diff --git a/conf/app.yml b/conf/app.yml index 927265a..c0f9b7e 100644 --- a/conf/app.yml +++ b/conf/app.yml @@ -28,8 +28,12 @@ superfeedr: deepzz disqus: shortname: deepzz publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg - url: https://disqus.com/api/3.0/threads/set.json + postscount: https://disqus.com/api/3.0/threads/set.json + postslist: https://disqus.com/api/3.0/threads/listPosts.json interval: 5 +# 热搜词配置 +hotwords: + - docker # 运行模式 mode: # you can fix certfile, keyfile, domain diff --git a/db.go b/db.go index 8e5dd40..111fa40 100644 --- a/db.go +++ b/db.go @@ -92,7 +92,7 @@ func init() { // 启动定时器 go timer() // 获取评论数量 - go CommentsCount() + go PostsCount() } // 读取或初始化帐号信息 diff --git a/disqus.go b/disqus.go index 37a292a..5cdc6db 100644 --- a/disqus.go +++ b/disqus.go @@ -22,18 +22,18 @@ type result struct { } } -func CommentsCount() { - if setting.Conf.Disqus.URL == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" { +func PostsCount() { + if setting.Conf.Disqus.PostsCount == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" { return } - baseUrl := setting.Conf.Disqus.URL + "?api_key=" + setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName + "&" + baseUrl := setting.Conf.Disqus.PostsCount + "?api_key=" + setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName + "&" var count, index int for index < len(Ei.Articles) { - logd.Debugf("count=====%d, index=======%d, length=======%d, bool=========%t", count, index, len(Ei.Articles), index < len(Ei.Articles) && count < 10) + logd.Debugf("count=====%d, index=======%d, length=======%d, bool=========%t", count, index, len(Ei.Articles), index < len(Ei.Articles) && count < 50) var threads []string - for ; index < len(Ei.Articles) && count < 20; index++ { + for ; index < len(Ei.Articles) && count < 50; index++ { artc := Ei.Articles[index] - threads = append(threads, fmt.Sprintf("thread=link:https://%s/post/%s.html", setting.Conf.Mode.Domain, artc.Slug)) + threads = append(threads, fmt.Sprintf("thread:ident=post-%s", artc.Slug)) count++ } count = 0 @@ -49,16 +49,16 @@ func CommentsCount() { logd.Error(err) break } + if resp.StatusCode != http.StatusOK { + logd.Error(string(b)) + break + } rst := result{} err = json.Unmarshal(b, &rst) if err != nil { logd.Error(err) break } - if rst.Code != SUCCESS { - logd.Error(rst.Code) - break - } for _, v := range rst.Response { i := strings.Index(v.Identifiers[0], "-") artc := Ei.MapArticles[v.Identifiers[0][i+1:]] @@ -67,5 +67,54 @@ func CommentsCount() { } } } - time.AfterFunc(time.Duration(setting.Conf.Disqus.Interval)*time.Hour, CommentsCount) + time.AfterFunc(time.Duration(setting.Conf.Disqus.Interval)*time.Hour, PostsCount) +} + +type postsList struct { + Cursor struct { + HasNext bool + Next string + } + Code int + Response []struct { + Parent int + Id string + CreatedAt string + Message string + Author struct { + Name string + ProfileUrl string + Avatar struct { + Cache string + } + } + } +} + +func PostsList(slug, cursor string) *postsList { + if setting.Conf.Disqus.PostsList == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" { + return nil + } + url := setting.Conf.Disqus.PostsList + "?limit=50&api_key=" + setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName + "&cursor=" + cursor + "&thread:ident=post-" + slug + resp, err := http.Get(url) + if err != nil { + return nil + } + defer resp.Body.Close() + b, err := ioutil.ReadAll(resp.Body) + if err != nil { + logd.Error(err) + return nil + } + if resp.StatusCode != http.StatusOK { + logd.Error(string(b)) + return nil + } + pl := &postsList{} + err = json.Unmarshal(b, pl) + if err != nil { + logd.Error(err) + return nil + } + return pl } diff --git a/front.go b/front.go index ccfa1db..6b18796 100644 --- a/front.go +++ b/front.go @@ -158,13 +158,12 @@ func HandleSearchPage(c *gin.Context) { h["CurrentPage"] = "search-post" q := c.Query("q") - start, err := strconv.Atoi(c.Query("start")) - if start < 1 || err != nil { - start = 1 - } if q != "" { + start, err := strconv.Atoi(c.Query("start")) + if start < 1 || err != nil { + start = 1 + } h["Word"] = q - h["HotWords"] = []string{"docker"} var result *ESSearchResult vals := c.Request.URL.Query() reg := regexp.MustCompile(`^[a-z]+:\w+$`) @@ -191,6 +190,8 @@ func HandleSearchPage(c *gin.Context) { h["Next"] = vals.Encode() } } + } else { + h["HotWords"] = setting.Conf.HotWords } c.Status(http.StatusOK) RenderHTMLFront(c, "search", h) @@ -242,41 +243,58 @@ func HandleBeacon(c *gin.Context) { } // 服务端获取评论详细 +type DisqusComments struct { + ErrNo int `json:"errno"` + ErrMsg string `json:"errmsg"` + Data struct { + Next string `json:"next"` + Total int `json:"total,omitempty"` + Comments []commentsDetail `json:"comments"` + } `json:"data"` +} + +type commentsDetail struct { + Id string `json:"id"` + Parent int `json:"parent"` + Name string `json:"name"` + Url string `json:"url"` + Avatar string `json:"avatar"` + CreatedAt string `json:"createdAt"` + CreatedAtStr string `json:"createdAtStr"` + Message string `json:"message"` +} + func HandleDisqus(c *gin.Context) { - slug := c.Query("slug") - logd.Debug(slug) - // TODO comments - var ss = map[string]interface{}{ - "errno": 0, - "errmsg": "", - "data": map[string]interface{}{ - "next": "", - "total": 3, - "comments": []map[string]interface{}{ - map[string]interface{}{ - "id": "2361914870", - "name": "Rekey Luo", - "parent": 0, - "url": "https://disqus.com/by/rekeyluo/", - "avatar": "//a.disquscdn.com/uploads/users/15860/7550/avatar92.jpg?1438917750", - "createdAt": "2015-11-16T05:00:02", - "createdAtStr": "9 months ago", - "message": "你最近对 http2 ssl 相关关注好多啊。", - }, - map[string]interface{}{ - "id": "2361915528", - "name": "Jerry Qu", - "parent": 0, - "url": "https://disqus.com/by/JerryQu/", - "avatar": "//a.disquscdn.com/uploads/users/1668/8837/avatar92.jpg?1472281172", - "createdAt": "2015-11-16T05:01:05", - "createdAtStr": "9 months ago", - "message": "嗯,最近对 web 性能优化这一块研究得比较多。", - }, - }, - }, + slug := c.Param("slug") + cursor := c.Query("cursor") + dcs := DisqusComments{} + postsList := PostsList(slug, cursor) + if postsList != nil { + dcs.ErrNo = postsList.Code + if postsList.Cursor.HasNext { + dcs.Data.Next = postsList.Cursor.Next + } + if cursor == "" { + dcs.Data.Total = Ei.MapArticles[slug].Count + } + dcs.Data.Comments = make([]commentsDetail, len(postsList.Response)) + for i, v := range postsList.Response { + dcs.Data.Comments[i] = commentsDetail{ + Id: v.Id, + Name: v.Author.Name, + Parent: v.Parent, + Url: v.Author.ProfileUrl, + Avatar: v.Author.Avatar.Cache, + CreatedAt: v.CreatedAt, + CreatedAtStr: ConvertStr(v.CreatedAt), + Message: v.Message, + } + } + } else { + dcs.ErrNo = FAIL + dcs.ErrMsg = "系统错误" } - c.JSON(http.StatusOK, ss) + c.JSON(http.StatusOK, dcs) } func RenderHTMLFront(c *gin.Context, name string, data gin.H) { diff --git a/helper.go b/helper.go index 133d315..dba494f 100644 --- a/helper.go +++ b/helper.go @@ -8,6 +8,9 @@ import ( "io/ioutil" "path" "regexp" + "time" + + "github.com/eiblog/utils/logd" ) const ( @@ -69,3 +72,42 @@ func PickFirstImage(html string) string { } return "" } + +// 2016-10-22T07:03:01 +const ( + JUST_NOW = "几秒前" + MINUTES_AGO = "%d分钟前" + HOURS_AGO = "%d小时前" + DAYS_AGO = "%d天前" + MONTH_AGO = "%d月前" + YEARS_AGO = "%d年前" +) + +func ConvertStr(str string) string { + t, err := time.Parse("2006-01-02T15:04:05", str) + if err != nil { + logd.Error(err, str) + return JUST_NOW + } + now := time.Now() + year1, month1, day1 := t.Date() + year2, month2, day2 := now.Date() + if y := year2 - year1; y > 0 { + return fmt.Sprintf(YEARS_AGO, y) + } + if m := month2 - month1; m > 0 { + return fmt.Sprintf(MONTH_AGO, m) + } + if d := day2 - day1; d > 0 { + return fmt.Sprintf(DAYS_AGO, d) + } + hour1, minute1, _ := t.Clock() + hour2, minute2, _ := now.Clock() + if h := hour2 - hour1; h > 0 { + return fmt.Sprintf(HOURS_AGO, h) + } + if m := minute2 - minute1; m > 0 { + return fmt.Sprintf(MINUTES_AGO, m) + } + return JUST_NOW +} diff --git a/setting/setting.go b/setting/setting.go index d17ac5b..73e75db 100644 --- a/setting/setting.go +++ b/setting/setting.go @@ -36,14 +36,16 @@ type Config struct { SearchURL string // elasticsearch 地址 Superfeedr string // superfeedr Disqus struct { // 获取文章数量相关 - ShortName string - PublicKey string - URL string - Interval int + ShortName string + PublicKey string + PostsCount string + PostsList string + Interval int } - Mode RunMode // 运行模式 - Twitter string // twitter地址 - Blogger struct { // 初始化数据 + HotWords []string // 热搜词 + Mode RunMode // 运行模式 + Twitter string // twitter地址 + Blogger struct { // 初始化数据 BlogName string SubTitle string BeiAn string diff --git a/views/st_blog_js.js b/views/st_blog_js.js index 30175b3..f4ea62e 100644 --- a/views/st_blog_js.js +++ b/views/st_blog_js.js @@ -1,3 +1,3 @@ {{define "blog_js"}} -var stringProto=String.prototype;stringProto.stripTags=function(){return this.replace(/<[^>]*>/gi,"")},stringProto.decode4Html=function(){var t=document.createElement("div");return t.innerHTML=this.stripTags(),t.childNodes[0]?t.childNodes[0].nodeValue||"":""},stringProto.queryUrl=function(t){var a=this.replace(/^[^?=]*\?/gi,"").split("#")[0],e={};return a.replace(/(^|&)([^&=]+)=([^&]*)/g,function(t,a,n,o){try{n=decodeURIComponent(n)}catch(s){}try{o=decodeURIComponent(o)}catch(s){}n in e?e[n] instanceof Array?e[n].push(o):e[n]=[e[n],o]:e[n]=/\[\]$/.test(n)?[o]:o}),t?e[t]:e},function(t){t.disqus_shortname="deepzz",$.each(["CURRENT_PAGE","CDN_DOMAIN"],function(a,e){t[e]="";var n=$("#"+e);n&&(t[e]=n.val())})}(this),function(t){function a(a){var e,n,o={selector:null,height:200};o=$.extend(o,a),e=o.height,n=function(){var a=$(t).scrollTop(),n=$(t).height()+a;$(o.selector).find("img[data-src]").each(function(){var t=$(this);setTimeout(function(){var o,s=t.offset(),i=t.height();s.top>n+e||s.top+i
'+(a.url?'':'')+'
'+a.message+'
';return e}function e(t){for(;t.length;){var e=[];t.forEach(function(t){var n=t.parent,o=s.find('ul[data-id="'+n+'"]');return o.length?void o.append(a(t)):void e.push(t)}),t=e}}function n(t){var a="";a=t.comments.length?'
本模式仅提供基础浏览功能。如需发表评论请点击这里(请确保你能流畅访问 disq.us | disquscdn.com | disqus.com)
    ':'

    没有找到任何评论数据~

    点此发表评论 \xbb

    ',s.html(a)}function o(){if(!i){i=!0;var a;a=r?"/disqus/"+t.simple_config.id+"/"+encodeURIComponent(r):"/disqus/"+t.simple_config.id,$.get(a,{},function(a){var o;i=!1,a&&0==a.errno?(r?e(a.data.comments):(n(a.data),e(a.data.comments),$(t).trigger("hashchange","scrollIntoView")),o=s.find(".load-more a"),a.data.next?o.removeClass("busy"):o.hide(),r=a.data.next,$(t).trigger("scroll")):s.html('

    获取数据失败,请稍后再试!

    ')})}}var s=$("#simple_thread"),i=!1,r="";s.on("click",".load-more a",function(t){t.preventDefault(),$(this).addClass("busy"),o()}).on("click",".time-ago",function(t){t.preventDefault(),location.hash="simple-"+$(this).data("id")}),$(t).on("hashchange",function(a,e){var n,o=location.hash.match(/#(?:comment|simple)-(\d+)/);o&&(n=s.find("#post-"+o[1]),n.length&&(s.find(".post-content.target").removeClass("target"),n.find("> .post-content").addClass("target"),e&&$(t).scrollTop(n.offset().top-90)))}),/(iPhone|Android)/.test(navigator.userAgent)&&s.addClass("mobile"),t.initSimpleThread=o}(window,document),function(t,a){return"127.0.0.1"!=a.domain&&"deepzz.com"!=a.domain?void (location.href=location.href.replace(/(https?:\/\/[^\/]+)\//i,"//deepzz.com/")):(function(){var t,a=location.search.queryUrl();"1"==a.clear_ls&&(delete a.clear_ls,t=$.param(a),setTimeout(function(){t?location.search=$.param(a):location.href=location.href.replace(/\?.*$/,"")},300))}(),void $(function(){lazyLoad({selector:"#content",height:100}),function(){var t=$("#content"),a=t.find("img"),e=t.width();a.each(function(){var t=$(this),a=0|t.attr("width"),n=0|t.attr("height"),o=t.prop("complete");a>e&&t.attr("height",Math.ceil(n/a*e)),t.prop("src")&&(o?t.addClass("loaded"):t.on("load",function(){t.addClass("loaded")}))})}(),function(){if("search-post"==CURRENT_PAGE){var t=$("#keyword");t.val()||t.focus()}}(),function(){var a,e,n,o,s=$("#disqus_thread"),i=$("#simple_thread"),r=!1,c=!1,l=$("#switch_thread_mode");l.length&&(t.disqus_config=function(){this.page.url=s.data("url"),this.page.identifier=s.data("identifier")},t.simple_config={id:i.data("id")},a=function(a){var e=new Image,n=setTimeout(function(){e.onerror=e.onload=null,a(-1)},2500);e.onerror=function(){clearTimeout(n),a(0)},e.onload=function(){clearTimeout(n),a(1)},e.src="https://disqus.com/favicon.ico?"+ +new Date,t.__disqus_img=e},e=function(){s.show(),i.hide(),l.html('「切换到评论浏览模式」'),localStorage.comment_type="disqus_thread",r||(r=!0,s.html("评论加载中...

    注:如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理;或者切换到评论浏览模式。"),$.ajax({url:t.CDN_DOMAIN+"/static/js/disqus_52ef5a.js",dataType:"script",cache:!0}),c||a(function(t){1>t&&(location.hash="simple_thread")}))},n=function(){s.hide(),i.show(),l.html('「切换到评论完整模式」'),localStorage.comment_type="simple_thread",c||(c=!0,i.html("评论加载中...

    注:本模式仅供浏览,如需发表评论请切换到评论完整模式。"),t.initSimpleThread())},o=function(){var t=location.hash;return"#simple_thread"==t||/#simple-\d+$/.test(t)?(n(),!0):"#disqus_thread"==t||/#comment-\d+$/.test(t)?(e(),!0):void 0},$(t).on("hashchange",o),setTimeout(function(){/ # (simple | comment) - \d + $ /.test(location.hash)&&$("#comments").get(0).scrollIntoView();var a=setInterval(function(){var i=s.offset().top,r=$(t).scrollTop();if(Math.abs(i-r)<1000){if(clearTimeout(a),o()){return}if("simple_thread"==localStorage.comment_type){return void n()}e()}},150)},250))}()}))}(this,document),function(t){$(function(){$(".entry-content pre").each(function(t){var a,e,n,o=$(this),s=o.find("code");if(s.length&&s.prop("className")&&(s.hasClass("language-html")&&(a="__HTML_CODE_"+t,s.prop("id",a),e=$(''),e.insertAfter(o)),s.html().split("\n").length>3&&s.prop("className").indexOf("language")>-1)){switch(n=s.prop("className").replace("language-","").toUpperCase()){case"XML":n="HTML";break;case"SHELL":n="BASH"}$(''+n+"").insertBefore(s)}}),$(".entry-content input.runcode").each(function(){var a=$(this);a.click(function(a){var e,n,o;a.preventDefault(),e=$("#"+$(this).data("id")).html().stripTags().decode4Html(),n=t.open("","_preview",""),o=n.document,o.open(),o.write(e),o.close()})}),$(".entry-content > pre code").each(function(i,block){hljs.highlightBlock(block)})})}(this),function(){$(function(){$(".entry-content img[data-replace]").each(function(){var t=$(this);t.click(function(){var a,e,n,o,s=1000*(t.data("dur")||20);t.css("cursor")&&(a="/static/img/blank.gif",e=t.prop("src"),n=t.data("replace"),t.prop("src",a),t.css("cursor",""),o=new Image,o.onload=function(){t.prop("src",n),setTimeout(function(){t.prop("src",e),t.css("cursor","pointer")},s)},o.src=n)}),t.css("cursor","pointer")})})}(this); +var stringProto=String.prototype;stringProto.stripTags=function(){return this.replace(/<[^>]*>/gi,"")},stringProto.decode4Html=function(){var t=document.createElement("div");return t.innerHTML=this.stripTags(),t.childNodes[0]?t.childNodes[0].nodeValue||"":""},stringProto.queryUrl=function(t){var a=this.replace(/^[^?=]*\?/gi,"").split("#")[0],e={};return a.replace(/(^|&)([^&=]+)=([^&]*)/g,function(t,a,n,o){try{n=decodeURIComponent(n)}catch(s){}try{o=decodeURIComponent(o)}catch(s){}n in e?e[n] instanceof Array?e[n].push(o):e[n]=[e[n],o]:e[n]=/\[\]$/.test(n)?[o]:o}),t?e[t]:e},function(t){t.disqus_shortname="deepzz",$.each(["CURRENT_PAGE","CDN_DOMAIN"],function(a,e){t[e]="";var n=$("#"+e);n&&(t[e]=n.val())})}(this),function(t){function a(a){var e,n,o={selector:null,height:200};o=$.extend(o,a),e=o.height,n=function(){var a=$(t).scrollTop(),n=$(t).height()+a;$(o.selector).find("img[data-src]").each(function(){var t=$(this);setTimeout(function(){var o,s=t.offset(),i=t.height();s.top>n+e||s.top+i
    '+(a.url?'':'')+'
    '+a.message+'
      ';return e}function e(t){for(;t.length;){var e=[];t.forEach(function(t){var n=t.parent,o=s.find('ul[data-id="'+n+'"]');return o.length?void o.append(a(t)):void e.push(t)}),t=e}}function n(t){var a="";a=t.comments.length?'
      本模式仅提供基础浏览功能。如需发表评论请点击这里(请确保你能流畅访问 disq.us | disquscdn.com | disqus.com)
        ':'

        没有找到任何评论数据~

        点此发表评论 \xbb

        ',s.html(a)}function o(){if(!i){i=!0;var a;a=r?"/disqus/"+t.simple_config.id+"?cursor="+r:"/disqus/"+t.simple_config.id,$.get(a,{},function(a){var o;i=!1,a&&0==a.errno?(r?e(a.data.comments):(n(a.data),e(a.data.comments),$(t).trigger("hashchange","scrollIntoView")),o=s.find(".load-more a"),a.data.next?o.removeClass("busy"):o.hide(),r=a.data.next,$(t).trigger("scroll")):s.html('

        获取数据失败,请稍后再试!

        ')})}}var s=$("#simple_thread"),i=!1,r="";s.on("click",".load-more a",function(t){t.preventDefault(),$(this).addClass("busy"),o()}).on("click",".time-ago",function(t){t.preventDefault(),location.hash="simple-"+$(this).data("id")}),$(t).on("hashchange",function(a,e){var n,o=location.hash.match(/#(?:comment|simple)-(\d+)/);o&&(n=s.find("#post-"+o[1]),n.length&&(s.find(".post-content.target").removeClass("target"),n.find("> .post-content").addClass("target"),e&&$(t).scrollTop(n.offset().top-90)))}),/(iPhone|Android)/.test(navigator.userAgent)&&s.addClass("mobile"),t.initSimpleThread=o}(window,document),function(t,a){return"127.0.0.1"!=a.domain&&"deepzz.com"!=a.domain?void (location.href=location.href.replace(/(https?:\/\/[^\/]+)\//i,"//deepzz.com/")):(function(){var t,a=location.search.queryUrl();"1"==a.clear_ls&&(delete a.clear_ls,t=$.param(a),setTimeout(function(){t?location.search=$.param(a):location.href=location.href.replace(/\?.*$/,"")},300))}(),void $(function(){lazyLoad({selector:"#content",height:100}),function(){var t=$("#content"),a=t.find("img"),e=t.width();a.each(function(){var t=$(this),a=0|t.attr("width"),n=0|t.attr("height"),o=t.prop("complete");a>e&&t.attr("height",Math.ceil(n/a*e)),t.prop("src")&&(o?t.addClass("loaded"):t.on("load",function(){t.addClass("loaded")}))})}(),function(){if("search-post"==CURRENT_PAGE){var t=$("#keyword");t.val()||t.focus()}}(),function(){var a,e,n,o,s=$("#disqus_thread"),i=$("#simple_thread"),r=!1,c=!1,l=$("#switch_thread_mode");l.length&&(t.disqus_config=function(){this.page.url=s.data("url"),this.page.identifier=s.data("identifier")},t.simple_config={id:i.data("id")},a=function(a){var e=new Image,n=setTimeout(function(){e.onerror=e.onload=null,a(-1)},2500);e.onerror=function(){clearTimeout(n),a(0)},e.onload=function(){clearTimeout(n),a(1)},e.src="https://disqus.com/favicon.ico?"+ +new Date,t.__disqus_img=e},e=function(){s.show(),i.hide(),l.html('「切换到评论浏览模式」'),localStorage.comment_type="disqus_thread",r||(r=!0,s.html("评论加载中...

        注:如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理;或者切换到评论浏览模式。"),$.ajax({url:t.CDN_DOMAIN+"/static/js/disqus_52ef5a.js",dataType:"script",cache:!0}),c||a(function(t){1>t&&(location.hash="simple_thread")}))},n=function(){s.hide(),i.show(),l.html('「切换到评论完整模式」'),localStorage.comment_type="simple_thread",c||(c=!0,i.html("评论加载中...

        注:本模式仅供浏览,如需发表评论请切换到评论完整模式。"),t.initSimpleThread())},o=function(){var t=location.hash;return"#simple_thread"==t||/#simple-\d+$/.test(t)?(n(),!0):"#disqus_thread"==t||/#comment-\d+$/.test(t)?(e(),!0):void 0},$(t).on("hashchange",o),setTimeout(function(){/ # (simple | comment) - \d + $ /.test(location.hash)&&$("#comments").get(0).scrollIntoView();var a=setInterval(function(){var i=s.offset().top,r=$(t).scrollTop();if(Math.abs(i-r)<1000){if(clearTimeout(a),o()){return}if("simple_thread"==localStorage.comment_type){return void n()}e()}},150)},250))}()}))}(this,document),function(t){$(function(){$(".entry-content pre").each(function(t){var a,e,n,o=$(this),s=o.find("code");if(s.length&&s.prop("className")&&(s.hasClass("language-html")&&(a="__HTML_CODE_"+t,s.prop("id",a),e=$(''),e.insertAfter(o)),s.html().split("\n").length>3&&s.prop("className").indexOf("language")>-1)){switch(n=s.prop("className").replace("language-","").toUpperCase()){case"XML":n="HTML";break;case"SHELL":n="BASH"}$(''+n+"").insertBefore(s)}}),$(".entry-content input.runcode").each(function(){var a=$(this);a.click(function(a){var e,n,o;a.preventDefault(),e=$("#"+$(this).data("id")).html().stripTags().decode4Html(),n=t.open("","_preview",""),o=n.document,o.open(),o.write(e),o.close()})}),$(".entry-content > pre code").each(function(i,block){hljs.highlightBlock(block)})})}(this),function(){$(function(){$(".entry-content img[data-replace]").each(function(){var t=$(this);t.click(function(){var a,e,n,o,s=1000*(t.data("dur")||20);t.css("cursor")&&(a="/static/img/blank.gif",e=t.prop("src"),n=t.data("replace"),t.prop("src",a),t.css("cursor",""),o=new Image,o.onload=function(){t.prop("src",n),setTimeout(function(){t.prop("src",e),t.css("cursor","pointer")},s)},o.src=n)}),t.css("cursor","pointer")})})}(this); {{end}}