diff --git a/js/main.js b/js/main.js index 0545730..5a586e7 100644 --- a/js/main.js +++ b/js/main.js @@ -15,13 +15,20 @@ $(document).ready(() => { let path = document.location.pathname; - console.log("pathname: ", path); - - if(path === "/" || path === "" || path === "/index.html"){ - path = "/home"; - } setPage(path); + + $("nav > a").each((i, elmt) => { + const href = $(elmt).attr("href"); + if(href[0] === "/"){ + $(elmt).bind("click", () => { + // window.location.pathname = href; + history.pushState(null, null, href); + setPage(href); + return false; + }) + } + }) }) @@ -37,6 +44,10 @@ function setPage(path){ sanitize: false, }; + if(path === "/" || path === "" || path === "/index.html"){ + path = "/home"; + } + $.ajax("/pages"+path+".md") .done((res) => { $("#article-container").html(res); @@ -54,8 +65,10 @@ function setPage(path){ return res; })); }); - - + }) + .fail((err) => { + $("#article-container").html(`

Error ${err.status} :'(

${err.statusText}
${err.responseText}

`); + console.error(err); }); }