From 59f937b8682a11dca8e80a410a612a7bcc7c1e9c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 23 Feb 2019 16:30:23 +0100 Subject: [PATCH] make the blog data not be cached --- scripts/blog.js | 81 ++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/scripts/blog.js b/scripts/blog.js index ae8cd69..0e351f7 100644 --- a/scripts/blog.js +++ b/scripts/blog.js @@ -1,45 +1,50 @@ let converter = new showdown.Converter(); -$.getJSON("blog/posts.json", function (json) { - let list = $('#blog-list'); - for (let i = json.length - 1; i >= 0; i--) { - var obj = json[i]; - let id = obj["id"]; +$.ajax({ + dataType: "json", + url: "blog/posts.json", + cache: false, + 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 = ""; - p += ''; - p += '
'; - p += '
'; - p += '

' + obj["name"] + '

'; - p += '
'; - p += '' + obj["date"] + ""; - var discussLink = obj["discuss"]; - if (discussLink) - p += '' - p += '
'; - list.append(p); + let p = ""; + p += ''; + p += '
'; + p += '
'; + p += '

' + obj["name"] + '

'; + p += '
'; + p += '' + obj["date"] + ""; + var discussLink = obj["discuss"]; + if (discussLink) + p += '' + p += '
'; + list.append(p); - $("#blog-button-" + id).on('click', function () { - var post = $("#blog-post-" + id); - if (post.html() !== "") { - post.html(""); - var discuss = $("#blog-discuss-" + id); - if (discuss.length) - discuss.html(""); - history.pushState(null, null, "#blog"); - } else { - openBlogPost(id); - history.pushState(null, null, "#blog-" + id); + $("#blog-button-" + id).on('click', function () { + var post = $("#blog-post-" + id); + if (post.html() !== "") { + post.html(""); + var discuss = $("#blog-discuss-" + id); + if (discuss.length) + discuss.html(""); + history.pushState(null, null, "#blog"); + } else { + openBlogPost(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) } } });