2020-09-30 00:24:37 +02:00
|
|
|
$("#blog-archive-button").on("click", function () {
|
|
|
|
let archive = $('#blog-archive');
|
|
|
|
archive.toggle();
|
|
|
|
$(this).html((archive.is(":visible") ? "Hide" : "Show") + " archived posts");
|
|
|
|
});
|
|
|
|
|
2019-02-23 16:30:23 +01:00
|
|
|
$.ajax({
|
|
|
|
dataType: "json",
|
2021-03-11 03:44:50 +01:00
|
|
|
url: "blog/src/posts.json",
|
2019-02-23 16:30:23 +01:00
|
|
|
cache: false,
|
|
|
|
success: function (json) {
|
2021-03-17 03:10:25 +01:00
|
|
|
populateBlog(json, "All");
|
2021-03-17 03:07:12 +01:00
|
|
|
forceToAnchor();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-17 03:10:25 +01:00
|
|
|
function populateBlog(json, cat) {
|
2021-03-17 03:07:12 +01:00
|
|
|
let archive = $('#blog-archive');
|
|
|
|
let list = $('#blog-list');
|
|
|
|
let cats = $('#blog-cats');
|
|
|
|
archive.html("");
|
|
|
|
list.html("");
|
|
|
|
cats.html("");
|
|
|
|
|
2021-03-17 03:10:25 +01:00
|
|
|
addCatButton(json, cats, "All");
|
|
|
|
for (let i = json.length - 1; i >= 0; i--) {
|
|
|
|
var obj = json[i];
|
|
|
|
addCatButton(json, cats, obj.cat);
|
2021-03-17 03:07:12 +01:00
|
|
|
if (cat == "All" || obj.cat == cat) {
|
2019-02-23 16:30:23 +01:00
|
|
|
let p = "";
|
|
|
|
p += '<div class="card bg-light blog-entry rounded-0">';
|
|
|
|
p += '<div class="card-body">';
|
2021-03-17 03:07:12 +01:00
|
|
|
p += '<h4 class="card-title blog-title"><a class="blog-button" href="/blog/' + obj.id + '">' + obj.name + '</a></h4>';
|
2019-11-20 22:17:58 +01:00
|
|
|
p += '<div class="card-text text-muted blog-summary">' + obj.summary + '</div>';
|
|
|
|
p += '<span class="text-muted project-status">' + obj.date + "</span>";
|
2021-03-17 03:07:12 +01:00
|
|
|
p += '<span class="text-muted blog-cat">' + obj.cat + "</span>";
|
2019-02-23 16:30:23 +01:00
|
|
|
p += '</div></div>';
|
2020-09-30 00:24:37 +02:00
|
|
|
if (obj.archived) {
|
|
|
|
archive.append(p);
|
|
|
|
} else {
|
|
|
|
list.append(p);
|
|
|
|
}
|
2019-02-17 01:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-17 03:07:12 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 03:10:25 +01:00
|
|
|
function addCatButton(json, cats, cat) {
|
2021-03-17 03:07:12 +01:00
|
|
|
let catAnchor = `blog-cat-${cat.toLowerCase().replace(" ", "_")}`;
|
|
|
|
if (!$(`#${catAnchor}`).length) {
|
|
|
|
cats.append(`<button type="button" class="btn btn-link blog-cat-button" id=${catAnchor}>${cat}</button>`);
|
|
|
|
$(`#${catAnchor}`).on('click', function () {
|
2021-03-17 03:10:25 +01:00
|
|
|
populateBlog(json, cat);
|
2021-03-17 03:07:12 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|