make the blog data not be cached

This commit is contained in:
Ellpeck 2019-02-23 16:30:23 +01:00
parent 6b1841beb6
commit 59f937b868

View file

@ -1,45 +1,50 @@
let converter = new showdown.Converter(); let converter = new showdown.Converter();
$.getJSON("blog/posts.json", function (json) { $.ajax({
let list = $('#blog-list'); dataType: "json",
for (let i = json.length - 1; i >= 0; i--) { url: "blog/posts.json",
var obj = json[i]; cache: false,
let id = obj["id"]; success: function (json) {
let list = $('#blog-list');
for (let i = json.length - 1; i >= 0; i--) {
var obj = json[i];
let id = obj["id"];
let p = ""; let p = "";
p += '<a class="blog-anchor" id="blog-' + id + '"></a>'; p += '<a class="blog-anchor" id="blog-' + id + '"></a>';
p += '<div class="card bg-light blog-entry rounded-0">'; p += '<div class="card bg-light blog-entry rounded-0">';
p += '<div class="card-body">'; p += '<div class="card-body">';
p += '<a class="blog-button" id="blog-button-' + id + '"><h2 class="card-title">' + obj["name"] + '</h2></a>'; p += '<a class="blog-button" id="blog-button-' + id + '"><h2 class="card-title">' + obj["name"] + '</h2></a>';
p += '<div class="card-text" id="blog-post-' + id + '"></div>'; p += '<div class="card-text" id="blog-post-' + id + '"></div>';
p += '<span class="text-muted project-status">' + obj["date"] + "</span>"; p += '<span class="text-muted project-status">' + obj["date"] + "</span>";
var discussLink = obj["discuss"]; var discussLink = obj["discuss"];
if (discussLink) if (discussLink)
p += '<a href="' + discussLink + '" class="blog-discuss" id="blog-discuss-' + id + '"></a>' p += '<a href="' + discussLink + '" class="blog-discuss" id="blog-discuss-' + id + '"></a>'
p += '</div></div>'; p += '</div></div>';
list.append(p); list.append(p);
$("#blog-button-" + id).on('click', function () { $("#blog-button-" + id).on('click', function () {
var post = $("#blog-post-" + id); var post = $("#blog-post-" + id);
if (post.html() !== "") { if (post.html() !== "") {
post.html(""); post.html("");
var discuss = $("#blog-discuss-" + id); var discuss = $("#blog-discuss-" + id);
if (discuss.length) if (discuss.length)
discuss.html(""); discuss.html("");
history.pushState(null, null, "#blog"); history.pushState(null, null, "#blog");
} else { } else {
openBlogPost(id); openBlogPost(id);
history.pushState(null, null, "#blog-" + id); history.pushState(null, null, "#blog-" + id);
}
});
}
if (window.location.hash.startsWith("#blog-")) {
var anchor = $(window.location.hash);
if (anchor.length) {
openBlogPost(window.location.hash.substring(6));
$('html, body').animate({
scrollTop: anchor.offset().top
}, 0)
} }
});
}
if (window.location.hash.startsWith("#blog-")) {
var anchor = $(window.location.hash);
if (anchor.length) {
openBlogPost(window.location.hash.substring(6));
$('html, body').animate({
scrollTop: anchor.offset().top
}, 0)
} }
} }
}); });