$("#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) { populateBlog(json, "All"); forceToAnchor(); } }); function populateBlog(json, cat) { let archive = $('#blog-archive'); let list = $('#blog-list'); let cats = $('#blog-cats'); archive.html(""); list.html(""); cats.html(""); addCatButton(json, cats, "All"); for (let i = json.length - 1; i >= 0; i--) { let obj = json[i]; addCatButton(json, cats, obj.cat); if (cat === "All" || obj.cat === cat) { let p = /*html*/ `

${obj.name}

${obj.summary}
${obj.date} ${obj.cat}
`; if (obj.archived) { archive.append(p); } else { list.append(p); } } } } function addCatButton(json, cats, cat) { let catAnchor = `blog-cat-${cat.toLowerCase().replace(" ", "_")}`; if (!$(`#${catAnchor}`).length) { cats.append( /*html*/ ``); $(`#${catAnchor}`).on('click', function () { populateBlog(json, cat); }); } }