Web/scripts/blog.js
Ell 6be0f6cbaf
All checks were successful
Web/pipeline/head This commit looks good
moved blog sources into blog/src
2021-03-11 03:44:50 +01:00

33 lines
No EOL
1.1 KiB
JavaScript

$("#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 list = $('#blog-list');
let archive = $('#blog-archive');
list.html("");
archive.html("");
for (let i = json.length - 1; i >= 0; i--) {
var obj = json[i];
let p = "";
p += '<div class="card bg-light blog-entry rounded-0">';
p += '<div class="card-body">';
p += '<h4 class="card-title"><a class="blog-button" href="/blog/' + obj.id + '">' + obj.name + '</a></h4>';
p += '<div class="card-text text-muted blog-summary">' + obj.summary + '</div>';
p += '<span class="text-muted project-status">' + obj.date + "</span>";
p += '</div></div>';
if (obj.archived) {
archive.append(p);
} else {
list.append(p);
}
}
forceToAnchor();
}
});