2019-05-01 20:10:56 +02:00
|
|
|
let converter = new showdown.Converter({
|
2019-05-01 20:13:43 +02:00
|
|
|
parseImgDimensions: true,
|
2019-10-03 15:15:25 +02:00
|
|
|
headerLevelStart: 3,
|
|
|
|
extensions: ["prettify"]
|
2019-05-01 20:10:56 +02:00
|
|
|
});
|
2019-02-23 16:30:23 +01:00
|
|
|
$.ajax({
|
|
|
|
dataType: "json",
|
|
|
|
url: "blog/posts.json",
|
|
|
|
cache: false,
|
|
|
|
success: function (json) {
|
|
|
|
let list = $('#blog-list');
|
2019-06-01 22:26:20 +02:00
|
|
|
list.html("");
|
2019-02-23 16:30:23 +01:00
|
|
|
for (let i = json.length - 1; i >= 0; i--) {
|
2019-10-04 15:51:42 +02:00
|
|
|
var obj = json[i];
|
2019-02-23 16:30:23 +01:00
|
|
|
let id = obj["id"];
|
2019-02-17 01:46:41 +01:00
|
|
|
|
2019-02-23 16:30:23 +01:00
|
|
|
let p = "";
|
|
|
|
p += '<a class="blog-anchor" id="blog-' + id + '"></a>';
|
|
|
|
p += '<div class="card bg-light blog-entry rounded-0">';
|
|
|
|
p += '<div class="card-body">';
|
|
|
|
p += '<a class="blog-button" id="blog-button-' + id + '"><h2 class="card-title">' + obj["name"] + '</h2></a>';
|
2019-10-09 15:51:43 +02:00
|
|
|
p += '<a class="reading-mode" href="/blog-' + id + '" id="reading-mode-' + id + '"></a>';
|
2019-10-03 13:29:55 +02:00
|
|
|
p += '<div class="card-text text-muted blog-summary" id="blog-summary-' + id + '">' + obj["summary"] + '</div>';
|
2019-02-23 16:30:23 +01:00
|
|
|
p += '<div class="card-text" id="blog-post-' + id + '"></div>';
|
|
|
|
p += '<span class="text-muted project-status">' + obj["date"] + "</span>";
|
2019-10-04 15:51:42 +02:00
|
|
|
var discussLink = obj["discuss"];
|
2019-02-23 16:30:23 +01:00
|
|
|
if (discussLink)
|
|
|
|
p += '<a href="' + discussLink + '" class="blog-discuss" id="blog-discuss-' + id + '"></a>'
|
|
|
|
p += '</div></div>';
|
|
|
|
list.append(p);
|
2019-02-17 01:46:41 +01:00
|
|
|
|
2019-02-23 16:30:23 +01:00
|
|
|
$("#blog-button-" + id).on('click', function () {
|
2019-10-04 15:51:42 +02:00
|
|
|
var post = $("#blog-post-" + id);
|
2019-02-23 16:30:23 +01:00
|
|
|
if (post.html() !== "") {
|
|
|
|
post.html("");
|
2019-10-04 15:51:42 +02:00
|
|
|
var discuss = $("#blog-discuss-" + id);
|
2019-02-23 16:30:23 +01:00
|
|
|
if (discuss.length)
|
|
|
|
discuss.html("");
|
2019-10-03 13:29:55 +02:00
|
|
|
$("#blog-summary-" + id).show();
|
2019-10-09 15:51:43 +02:00
|
|
|
$("#reading-mode-" + id).html("");
|
2019-10-04 15:51:42 +02:00
|
|
|
history.pushState(null, null, "#blog");
|
2019-02-23 16:30:23 +01:00
|
|
|
} else {
|
2019-10-04 15:51:42 +02:00
|
|
|
openBlogPost(id);
|
2019-02-23 16:30:23 +01:00
|
|
|
history.pushState(null, null, "#blog-" + id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-02-17 01:56:31 +01:00
|
|
|
|
2019-10-04 15:51:42 +02:00
|
|
|
if (window.location.hash.startsWith("#blog-")) {
|
|
|
|
var anchor = $(window.location.hash);
|
|
|
|
if (anchor.length) {
|
|
|
|
openBlogPost(window.location.hash.substring(6), function () {
|
2019-10-02 14:40:00 +02:00
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: anchor.offset().top
|
|
|
|
}, 0)
|
|
|
|
});
|
2019-02-23 16:30:23 +01:00
|
|
|
}
|
2019-02-17 01:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-17 01:46:41 +01:00
|
|
|
});
|
|
|
|
|
2019-10-04 15:51:42 +02:00
|
|
|
function openBlogPost(id, onDone) {
|
2019-02-17 01:46:41 +01:00
|
|
|
$.get("blog/" + id + ".md", function (markdown) {
|
|
|
|
let html = converter.makeHtml(markdown);
|
|
|
|
$("#blog-post-" + id).html(html);
|
2019-02-17 13:07:19 +01:00
|
|
|
|
2019-10-04 15:51:42 +02:00
|
|
|
var discuss = $("#blog-discuss-" + id);
|
2019-02-17 13:07:19 +01:00
|
|
|
if (discuss.length)
|
|
|
|
discuss.html("Discuss this post");
|
2019-10-03 13:29:55 +02:00
|
|
|
$("#blog-summary-" + id).hide();
|
2019-10-09 15:51:43 +02:00
|
|
|
$("#reading-mode-" + id).html("Reading Mode");
|
2019-10-02 14:40:00 +02:00
|
|
|
|
2019-10-03 15:15:25 +02:00
|
|
|
PR.prettyPrint();
|
2019-10-02 14:40:00 +02:00
|
|
|
if (onDone)
|
|
|
|
onDone();
|
2019-02-17 01:46:41 +01:00
|
|
|
});
|
|
|
|
}
|