var talaria=function(t){"use strict";function e(t){this.name="RateLimitedError",this.message=t||"Rate-Limit exceeded."}function a(t){this.name="NotFoundError",this.message=t||"Object not found."}function n(t){return 403===t.status}var r={},o={COMMENTABLE_CONTENT_PATH_PREFIX:"_posts/",CONTENT_SUFFIX:".md",CACHE_TIMEOUT:36e5,PAGINATION_SCHEME:/\/page\d+\//,LOCAL_STORAGE_SUPPORTED:!1,PERMALINK_IDENTIFIER:"a.permalink",PERMALINK_STYLE:/[\.\w\-_:\/]+\/(\d+)\/(\d+)\/(\d+)\/([\w\-\.]+)$/},i=function(){switch(r.PERMALINK_STYLE){case"pretty":return/[\.\w\-_:\/]+\/(\d+)\/(\d+)\/(\d+)\/([\w\-\.]+)\/$/;case"date":return/[\.\w\-_:\/]+\/(\d+)\/(\d+)\/(\d+)\/([\w\-\.]+)\.html$/;case"none":if(!r.USE_GISTS)throw new Error("When using commit-based comments, talaria requires the use of permalinks that include the date of the post");return/[\.\w\-_:\/]+\/([\w\-\.]+)\.html$/;default:return r.PERMALINK_STYLE}},c=function(t){return t.replace(r.PERMALINK_STYLE,r.COMMENTABLE_CONTENT_PATH_PREFIX+"$1-$2-$3-$4"+r.CONTENT_SUFFIX)},m=function(t){return t.substr(0,7)},s=function(){try{return sessionStorage.setItem("dummy","dummy"),sessionStorage.removeItem("dummy"),!0}catch(t){return!1}},u=function(t){return(new Date).getTime()-t.timestamp>r.CACHE_TIMEOUT},l=function(e){var a;return r.LOCAL_STORAGE_SUPPORTED&&(a=sessionStorage.getItem(e),a&&(a=JSON.parse(a),!u(a)))?t.resolve(a.commentData):t.reject("cache miss")},d=function(t,e){r.LOCAL_STORAGE_SUPPORTED&&sessionStorage.setItem(t,JSON.stringify({timestamp:(new Date).getTime(),commentData:e}))},h=function(t){return t.length>0?t.sort(function(t,e){return new Date(t.commit.committer.date)>new Date(e.commit.committer.date)})[0]:void 0},p=function(t,e){var a=function(t){return 1===t?"":"s"},n=6e4,r=60*n,o=24*r,i=30*o,c=365*o,m=15e3,s=t-e,u=0;return n>s?m>s?" just now":Math.round(s/1e3)+" seconds ago":r>s?(u=Math.round(s/n),u+" minute"+a(u)+" ago"):o>s?(u=Math.round(s/r),u+" hour"+a(u)+" ago"):i>s?(u=Math.round(s/o),u+" day"+a(u)+" ago"):c>s?(u=Math.round(s/i),"about "+u+" month"+a(u)+" ago"):(u=Math.round(s/c),"about "+u+" year"+a(u)+" ago")},f=function(t,e,a){document.getElementById("talaria-show-"+t).addEventListener("click",function(e){a&&(e.preventDefault(),document.querySelector("#talaria-wrap-"+t+" .talaria-comment-list-wrapper").classList.remove("hide"),this.classList.add("hide"))}),document.getElementById("talaria-add-"+t).addEventListener("click",function(){r.LOCAL_STORAGE_SUPPORTED&&sessionStorage.removeItem(e)})},E=function(t){t=t||{};for(var e=1;e=200&&n.status<400?e(JSON.parse(n.responseText)):a(n)},n.onerror=function(){a(n)},n.send()})},T=function(t){for(var e=t;null!==e.parentNode;){if("ARTICLE"===e.parentElement.tagName)return e.parentNode;e=e.parentNode}return e};e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,a.prototype=Object.create(Error.prototype),a.prototype.constructor=a;var _=function(t,e,a,n){var r=document.createElement("div");return n=0===a||n,r.innerHTML='
Unable to retrieve comments for this post.

Comments via github

',r},I=function(t){var e,a=(new Date).getTime();return e=void 0!==t.commit_id?' commented on '+m(t.commit_id)+"":' wrote','
'+t.user.login+""+e+' '+p(a,new Date(t.updated_at))+'
'+(t.body_html||t.body)+"
"},g=function(){return O().map(function(t){return l(t.getAttribute("href")).then(function(e){return A(t,e),e.comments}).catch(function(){return S(t).map(function(t){return L(t)}).reduce(function(t,e){var a=e.commit;return t.comments=t.comments.concat(e.comments),t.commits.push({sha:a.sha,commit:{committer:{date:a.commit.committer.date},comment_count:a.commit.comment_count}}),t},{comments:[],commits:[]}).then(function(e){var a={comments:e.comments,commits:e.commits};return d(t.getAttribute("href"),a),A(t,a),e.comments}).catch(e,function(){var e=T(t),a=_("","",0,!1);e.appendChild(a);var n=e.querySelector("div.talaria-load-error"),r=e.querySelector("div.talaria-comment-count");n.innerHTML="The Github API rate-limit has been reached. Unable to load comments.",n.classList.remove("hide"),r.classList.add("hide")}).catch(a,function(){var e=T(t),a=_("","",0,!1);e.appendChild(a);var n=e.querySelector("div.talaria-load-error"),r=e.querySelector("div.talaria-comment-count");n.innerHTML="Unable to find commits for this post.",n.classList.remove("hide"),r.classList.add("hide")})})},{concurrency:2})},O=function(){for(var e=[],a=document.querySelectorAll(r.PERMALINK_IDENTIFIER),n=0;n0)},N=function(){return v(r.GIST_MAPPINGS).then(function(t){return b(t)}).map(function(t){var e=t.gist;return l(e.permalink).catch(function(){return M(e)}).then(function(e){return w(t.linkobj,e),e}).catch(function(a){return e.comments=[],P(t.linkobj,a,e),e})},{concurrency:2}).catch(function(){return R(),[]})},M=function(t){return v("https://api.github.com/gists/"+t.id+"/comments").then(function(e){return t.comments=e,d(t.permalink,t),t})},b=function(t){var e,a=[];for(var n in t)if(t.hasOwnProperty(n)){e=t[n];var o=document.querySelector(r.PERMALINK_IDENTIFIER+'[href="'+e.permalink+'"]');null!==o&&a.push({gist:t[n],linkobj:o})}return a},R=function(){for(var t=_("","",0,!1),e=document.querySelectorAll(r.PERMALINK_IDENTIFIER),a=0;a0)},y=function(t){r=E({},o,t),r.GISTS_API_ENDPOINT="https://api.github.com/users/"+r.GITHUB_USERNAME+"/gists",r.COMMIT_API_ENDPOINT="https://api.github.com/repos/"+r.GITHUB_USERNAME+"/"+r.REPOSITORY_NAME+"/commits",r.REPO_COMMIT_URL_ROOT="https://github.com/"+r.GITHUB_USERNAME+"/"+r.REPOSITORY_NAME+"/commit/",r.GIST_URL_ROOT="https://gist.github.com/"+r.GITHUB_USERNAME+"/",r.PERMALINK_STYLE=i()},C=function(t){return y(t),s&&(r.LOCAL_STORAGE_SUPPORTED=!0),r.USE_GISTS?N():g()};return{init:C}}(P);