$("#blog-archive-button").on("click", function () { let archive = $('#blog-archive'); archive.toggle(); $(this).html((archive.is(":visible") ? "Hide" : "Show") + " archived posts"); }); $.ajax({ dataType: "json", url: "blog/src/posts.json", cache: false, success: function (json) { let category = window.location.hash.match(/#blog-(.+)/); populateBlog(json, category && decodeURI(category[1]) || "featured"); forceToAnchor(); } }); function populateBlog(json, currCat) { let anchors = $('#blog-cat-anchors'); let archive = $('#blog-archive'); let list = $('#blog-list'); let cats = $('#blog-cats'); anchors.html(""); archive.html(""); list.html(""); cats.html(""); // force all and featured categories to be first addCategory(json, cats, anchors, "All Posts", currCat); addCategory(json, cats, anchors, "Featured", currCat); for (let i = json.length - 1; i >= 0; i--) { let post = json[i]; for (let cat of post.cat) addCategory(json, cats, anchors, cat, currCat); let catIds = post.cat.map(c => c.toLowerCase().replace(" ", "-")); if (currCat === "all-posts" || catIds.includes(currCat)) { let p = /*html*/ `