const scrollLimit=150;function goToURL(e){let t=e.split("/");if("/blog/"!==e&&"/blog"!==e){if("post"!==t[2])return"category"===t[2]?t[3]?void loadPostsByCategory(t[t.length-1]):void loadAllCategories():void show404();loadIndividualPost(t[t.length-1]).catch((e=>console.log(e)))}else loadHomeContent()}function createLargePost(e){let t=document.createElement("div");t.classList.add("outerContent");let n=document.createElement("img");n.className="banner",n.src=e.headerImg,n.alt=e.title,t.appendChild(n);let a=document.createElement("div");a.classList.add("content");let o=document.createElement("div");o.classList.add("postContent");let s="";return e.categories.split(", ").forEach((t=>{s+=`${t}`,e.categories.split(", ").length>1&&(s+=", ")})),window.categories=s,o.innerHTML=`\n

${e.title}

\n

Last updated: ${e.dateModified} | ${s}

\n

${e.abstract}

\n See Post\n `,a.appendChild(o),t.appendChild(a),t}function loadHomeContent(){fetch("/api/blog/post").then((e=>e.json().then((e=>{for(let t=0;te.json())),await fetch("/api/blog/post/featured").then((e=>e.json()))]}function csvToArray(e){let t="",n=[""],a=0,o=!0,s=null;for(s of e)'"'===s?(o&&s===t&&(n[a]+=s),o=!o):","===s&&o?s=n[++a]="":"\n"===s&&o?("\r"===t&&(row[a]=row[a].slice(0,-1)),n=n[++r]=[s=""],a=0):n[a]+=s,t=s;return n}async function getCategories(){let e=await fetch("/api/blog/categories").then((e=>e.json())),t=[];return e.forEach((e=>t.push(csvToArray(e.categories)))),t}function createCategories(e){let t="";return e.forEach((e=>e.forEach((e=>t+=`${e}`)))),t}function createButtonCategories(e){let t="";return e.forEach((e=>e.forEach((e=>t+=`${e}`)))),t}async function createSideContent(){let e=await getLatestAndFeaturedPosts(),t=e[0],n=e[1],a=createCategories(await getCategories()),o=document.createElement("aside");return o.classList.add("sideContent"),o.innerHTML=`\n
\n
\n My professional picture taken in brighton near \n                                        north street at night wearing a beige jacket and checkered shirt\n

Rohit Pai

\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n

Avid Full Stack Dev | Uni of Notts Grad | Amateur Blogger

\n\n
\n \n \n
\n

categories

\n ${a}\n
\n `,o}async function loadIndividualPost(e){document.title="Rohit Pai - "+decodeURI(e),await fetch(`/api/blog/post/${e}`).then((async e=>{e.ok?await e.json().then((async e=>{let t=document.createElement("section");t.classList.add("post"),t.id="individualPost";let n=document.createElement("div");n.classList.add("mainContent");let a=document.createElement("article");a.innerHTML=`\n

${e.title}

\n
\n

Last updated: ${e.dateModified}

\n

${createButtonCategories([csvToArray(e.categories)])}

\n
\n
\n ${e.body}\n `;let o=document.createElement("section");o.classList.add("comments"),o.innerHTML='

Comments

\n
\n ',n.appendChild(a),n.appendChild(o);let s=await createSideContent();t.appendChild(n),t.appendChild(s),document.querySelector("#main").appendChild(t);var c,i;c=document,(i=c.createElement("script")).src="https://rohitpaiportfolio.disqus.com/embed.js",i.setAttribute("data-timestamp",+new Date),c.body.appendChild(i)})):show404()}))}function loadAllCategories(){}function loadPostsByCategory(e){document.title="Rohit Pai - "+decodeURI(e),fetch(`/api/blog/post/category/${e}`).then((t=>t.json().then((t=>{let n=document.createElement("section");n.classList.add("posts"),n.id="postsByCategory";let a=document.createElement("h1");a.innerHTML=e,n.appendChild(a);for(let e=0;e{goToURL(window.location.pathname)})),window.addEventListener("popstate",(e=>{goToURL(window.history.state)})),window.onscroll=()=>{document.body.scrollTop>=150||document.documentElement.scrollTop>=150?document.querySelector("nav").classList.add("scrolled"):document.querySelector("nav").classList.remove("scrolled")};