mirror of https://github.com/bearfm/site.git
1 line
947 B
JavaScript
1 line
947 B
JavaScript
function convertCamelCaseToReadable(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/(\d{4}-\d{2}-\d{2})/g," $1").replace(/\b\w/g,e=>e.toUpperCase())}function blogIndex(){document.getElementById("blogIndex").innerHTML=null,document.getElementById("latestPost").innerHTML=null,fetch("/blogindex.txt").then(e=>e.text()).then(e=>{e=e.split("\n").filter(e=>""!==e.trim()).map(e=>{e=e.split(" ");return{timestamp:parseInt(e[0]),uri:e[1]||""}});e.sort((e,n)=>n.timestamp-e.timestamp);const l=document.createElement("ul");e.forEach(e=>{var n,o,t;e.uri&&(n=convertCamelCaseToReadable(o=e.uri.split("/").pop().replace(".html","")),"index"!==o.toLowerCase())&&(o=document.createElement("li"),(t=document.createElement("a")).href=e.uri.substring(e.uri.indexOf("/blog/")),t.textContent=n,o.appendChild(t),l.appendChild(o))}),document.getElementById("blogIndex").appendChild(l)}).catch(e=>{console.error("Error fetching and processing blog index:",e)})} |