From e739c04fb6175fd866cd0a90831200e8ad48e5c8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 6 May 2020 19:54:21 +0200 Subject: [PATCH] archived some posts --- blog/posts.json | 9 ++++++--- node/blog.js | 30 ++++++++++++++++++++++-------- scripts/blog.js | 2 ++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/blog/posts.json b/blog/posts.json index 0c72f0f..f0baf57 100644 --- a/blog/posts.json +++ b/blog/posts.json @@ -3,7 +3,8 @@ "summary": "The first post and how I created it", "id": "blogs_are_cool", "date": "2/17/2019", - "discuss": "https://twitter.com/Ellpeck/status/1096937184601538566" + "discuss": "https://twitter.com/Ellpeck/status/1096937184601538566", + "archived": true }, { "name": "Why You Should Mod Minecraft", @@ -31,7 +32,8 @@ "summary": "How moving from Java to C# taught me how horrible it is to create a cross-platform application with little to no knowledge or documentation", "id": "cross_platform_trainwreck", "date": "7/6/2019", - "discuss": "https://twitter.com/Ellpeck/status/1147502654236573697" + "discuss": "https://twitter.com/Ellpeck/status/1147502654236573697", + "archived": true }, { "name": "Big Projects", @@ -87,7 +89,8 @@ "summary": "About depression and what it feels like when I don't know what to do with myself", "id": "lows", "date": "10/20/2019", - "discuss": "https://twitter.com/Ellpeck/status/1186028260838334471" + "discuss": "https://twitter.com/Ellpeck/status/1186028260838334471", + "archived": true }, { "name": "Java Tutorial, Part 6: Inheritance", diff --git a/node/blog.js b/node/blog.js index 817003e..ab3c2a8 100644 --- a/node/blog.js +++ b/node/blog.js @@ -25,10 +25,12 @@ fs.readFile(folder + "index.html", function (_, data) { var nav = ""; nav += 'Back to Main Page'; - if (i > 0) - nav += 'Previous Post'; - if (i < json.length - 1) - nav += 'Next Post'; + let last = getAdjacentPost(json, i, -1); + if (last) + nav += 'Previous Post'; + let next = getAdjacentPost(json, i, 1); + if (next) + nav += 'Next Post'; document.getElementById("nav-items").innerHTML = nav; var c = ""; @@ -36,12 +38,13 @@ fs.readFile(folder + "index.html", function (_, data) { c += '
' c += '

' + post.name + '

'; c += '
' + if (post.archived) + c += "

This post has been archived.

" c += converter.makeHtml(content.toString()); c += '
'; c += '' + post.date + ""; - var discussLink = post.discuss; - if (discussLink) - c += 'Discuss this post' + if (post.discuss) + c += 'Discuss this post' c += '
'; document.getElementById("main").innerHTML = c; @@ -50,4 +53,15 @@ fs.readFile(folder + "index.html", function (_, data) { }); } }); -}); \ No newline at end of file +}); + +function getAdjacentPost(json, index, move) { + while (true) { + index += move; + let post = json[index]; + if (!post) + break; + if (!post.archived) + return post; + } +} \ No newline at end of file diff --git a/scripts/blog.js b/scripts/blog.js index a94f296..9ab326b 100644 --- a/scripts/blog.js +++ b/scripts/blog.js @@ -7,6 +7,8 @@ $.ajax({ list.html(""); for (let i = json.length - 1; i >= 0; i--) { var obj = json[i]; + if (obj.archived) + continue; let p = ""; p += '
';