added a featured category to the blog
All checks were successful
Web/pipeline/head This commit looks good

This commit is contained in:
Ell 2021-03-31 02:48:13 +02:00
parent bebf4fb309
commit 5de5fba62a
7 changed files with 55 additions and 51 deletions

View file

@ -2,7 +2,7 @@
"name": "Blogs are Cool, I Think", "name": "Blogs are Cool, I Think",
"summary": "The first post and how I created it", "summary": "The first post and how I created it",
"id": "blogs_are_cool", "id": "blogs_are_cool",
"cat": "Miscellaneous", "cat": ["Miscellaneous"],
"date": "2/17/2019", "date": "2/17/2019",
"discuss": "https://twitter.com/Ellpeck/status/1096937184601538566", "discuss": "https://twitter.com/Ellpeck/status/1096937184601538566",
"archived": true "archived": true
@ -11,7 +11,7 @@
"name": "Why You Should Mod Minecraft", "name": "Why You Should Mod Minecraft",
"summary": "About what makes Minecraft modding great and why you should probably try it if you enjoy programming", "summary": "About what makes Minecraft modding great and why you should probably try it if you enjoy programming",
"id": "why_you_should_mod_minecraft", "id": "why_you_should_mod_minecraft",
"cat": "Minecraft", "cat": ["Minecraft", "Programming"],
"date": "2/17/2019", "date": "2/17/2019",
"discuss": "https://twitter.com/Ellpeck/status/1097177774337462272" "discuss": "https://twitter.com/Ellpeck/status/1097177774337462272"
}, },
@ -19,7 +19,7 @@
"name": "Kindling the Reading Flame", "name": "Kindling the Reading Flame",
"summary": "About the Kindle, Harry Potter and what I like and dislike about them", "summary": "About the Kindle, Harry Potter and what I like and dislike about them",
"id": "reading", "id": "reading",
"cat": "Miscellaneous", "cat": ["Miscellaneous"],
"date": "3/22/2019", "date": "3/22/2019",
"discuss": "https://twitter.com/Ellpeck/status/1109102077911973888" "discuss": "https://twitter.com/Ellpeck/status/1109102077911973888"
}, },
@ -27,7 +27,7 @@
"name": "Small Projects", "name": "Small Projects",
"summary": "Why creating a small, unplanned project is sometimes good for you", "summary": "Why creating a small, unplanned project is sometimes good for you",
"id": "small_projects", "id": "small_projects",
"cat": "Programming", "cat": ["Programming"],
"date": "5/1/2019", "date": "5/1/2019",
"discuss": "https://twitter.com/Ellpeck/status/1123651624201871360" "discuss": "https://twitter.com/Ellpeck/status/1123651624201871360"
}, },
@ -35,7 +35,7 @@
"name": "About Cross-Platform and Motivation", "name": "About Cross-Platform and Motivation",
"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", "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", "id": "cross_platform_trainwreck",
"cat": "Programming", "cat": ["Programming"],
"date": "7/6/2019", "date": "7/6/2019",
"discuss": "https://twitter.com/Ellpeck/status/1147502654236573697", "discuss": "https://twitter.com/Ellpeck/status/1147502654236573697",
"archived": true "archived": true
@ -44,7 +44,7 @@
"name": "Big Projects", "name": "Big Projects",
"summary": "How a once small project I even created a post about turned into the first game I'm selling: Foe Frenzy", "summary": "How a once small project I even created a post about turned into the first game I'm selling: Foe Frenzy",
"id": "big_projects", "id": "big_projects",
"cat": "Programming", "cat": ["Programming"],
"date": "9/15/2019", "date": "9/15/2019",
"discuss": "https://twitter.com/Ellpeck/status/1173247686654517249" "discuss": "https://twitter.com/Ellpeck/status/1173247686654517249"
}, },
@ -52,7 +52,7 @@
"name": "How to make a Rock Bottom mod", "name": "How to make a Rock Bottom mod",
"summary": "My adventures back into a game I stopped working on about two years ago and how I start on a mod for it", "summary": "My adventures back into a game I stopped working on about two years ago and how I start on a mod for it",
"id": "rock_bottom_mod", "id": "rock_bottom_mod",
"cat": "Programming", "cat": ["Programming"],
"date": "10/3/2019", "date": "10/3/2019",
"discuss": "https://twitter.com/Ellpeck/status/1180092634410487808" "discuss": "https://twitter.com/Ellpeck/status/1180092634410487808"
}, },
@ -60,7 +60,7 @@
"name": "Java Tutorial, Part 1: Hello World", "name": "Java Tutorial, Part 1: Hello World",
"summary": "The first part of my post series for programming beginners where I explain how to write code in Java.", "summary": "The first part of my post series for programming beginners where I explain how to write code in Java.",
"id": "java_1", "id": "java_1",
"cat": "Java Tutorials", "cat": ["Java Tutorials", "Featured"],
"date": "10/10/2019", "date": "10/10/2019",
"discuss": "https://twitter.com/Ellpeck/status/1182080078827737088" "discuss": "https://twitter.com/Ellpeck/status/1182080078827737088"
}, },
@ -68,7 +68,7 @@
"name": "Java Tutorial, Part 2: Intro to Conditions and Loops", "name": "Java Tutorial, Part 2: Intro to Conditions and Loops",
"summary": "The second part of my post series for programming beginners. This one is all about conditions and loops.", "summary": "The second part of my post series for programming beginners. This one is all about conditions and loops.",
"id": "java_2", "id": "java_2",
"cat": "Java Tutorials", "cat": ["Java Tutorials"],
"date": "10/10/2019", "date": "10/10/2019",
"discuss": "https://twitter.com/Ellpeck/status/1182354544707198976" "discuss": "https://twitter.com/Ellpeck/status/1182354544707198976"
}, },
@ -76,7 +76,7 @@
"name": "Java Tutorial, Part 3: (Static) Methods", "name": "Java Tutorial, Part 3: (Static) Methods",
"summary": "In this Java tutorial for beginners, we cover what (static) methods, parameters and return types are.", "summary": "In this Java tutorial for beginners, we cover what (static) methods, parameters and return types are.",
"id": "java_3", "id": "java_3",
"cat": "Java Tutorials", "cat": ["Java Tutorials"],
"date": "10/11/2019", "date": "10/11/2019",
"discuss": "https://twitter.com/Ellpeck/status/1182775985885847558" "discuss": "https://twitter.com/Ellpeck/status/1182775985885847558"
}, },
@ -84,7 +84,7 @@
"name": "Java Tutorial, Part 4: Classes and Objects", "name": "Java Tutorial, Part 4: Classes and Objects",
"summary": "In this Java tutorial for beginners, we cover the basics of creating classes with a constructor, some fields and some methods and creating objects of them.", "summary": "In this Java tutorial for beginners, we cover the basics of creating classes with a constructor, some fields and some methods and creating objects of them.",
"id": "java_4", "id": "java_4",
"cat": "Java Tutorials", "cat": ["Java Tutorials"],
"date": "10/14/2019", "date": "10/14/2019",
"discuss": "https://twitter.com/Ellpeck/status/1183857460660101133" "discuss": "https://twitter.com/Ellpeck/status/1183857460660101133"
}, },
@ -92,7 +92,7 @@
"name": "Java Tutorial, Part 5: Things I Left Out So Far", "name": "Java Tutorial, Part 5: Things I Left Out So Far",
"summary": "In this Java tutorial for beginners, we cover some shorthands, some more data types, the difference between pass-by-reference and pass-by-value, null, as well as arrays and lists.", "summary": "In this Java tutorial for beginners, we cover some shorthands, some more data types, the difference between pass-by-reference and pass-by-value, null, as well as arrays and lists.",
"id": "java_5", "id": "java_5",
"cat": "Java Tutorials", "cat": ["Java Tutorials"],
"date": "10/17/2019", "date": "10/17/2019",
"discuss": "https://twitter.com/Ellpeck/status/1184894859133509632" "discuss": "https://twitter.com/Ellpeck/status/1184894859133509632"
}, },
@ -100,7 +100,7 @@
"name": "Lows", "name": "Lows",
"summary": "About depression and what it feels like when I don't know what to do with myself", "summary": "About depression and what it feels like when I don't know what to do with myself",
"id": "lows", "id": "lows",
"cat": "Miscellaneous", "cat": ["Miscellaneous"],
"date": "10/20/2019", "date": "10/20/2019",
"discuss": "https://twitter.com/Ellpeck/status/1186028260838334471", "discuss": "https://twitter.com/Ellpeck/status/1186028260838334471",
"archived": true "archived": true
@ -109,7 +109,7 @@
"name": "Java Tutorial, Part 6: Inheritance", "name": "Java Tutorial, Part 6: Inheritance",
"summary": "In this Java tutorial for beginners, we cover classes extending other classes and the instanceof keyword.", "summary": "In this Java tutorial for beginners, we cover classes extending other classes and the instanceof keyword.",
"id": "java_6", "id": "java_6",
"cat": "Java Tutorials", "cat": ["Java Tutorials"],
"date": "10/31/2019", "date": "10/31/2019",
"discuss": "https://twitter.com/Ellpeck/status/1189904487722487809" "discuss": "https://twitter.com/Ellpeck/status/1189904487722487809"
}, },
@ -117,7 +117,7 @@
"name": "Java Tutorial, Part 7: Overriding Methods", "name": "Java Tutorial, Part 7: Overriding Methods",
"summary": "In this Java tutorial for beginners, we cover overriding methods, calling superclass methods and toString().", "summary": "In this Java tutorial for beginners, we cover overriding methods, calling superclass methods and toString().",
"id": "java_7", "id": "java_7",
"cat": "Java Tutorials", "cat": ["Java Tutorials"],
"date": "11/26/2019", "date": "11/26/2019",
"discuss": "https://twitter.com/Ellpeck/status/1199339701640945664" "discuss": "https://twitter.com/Ellpeck/status/1199339701640945664"
}, },
@ -125,14 +125,14 @@
"name": "But Do You Really Care?", "name": "But Do You Really Care?",
"summary": "On taking a break from social media", "summary": "On taking a break from social media",
"id": "but_do_you_really_care", "id": "but_do_you_really_care",
"cat": "Miscellaneous", "cat": ["Miscellaneous"],
"date": "5/6/2020" "date": "5/6/2020"
}, },
{ {
"name": "Oh God, Please Don't Port Actually Additions", "name": "Oh God, Please Don't Port Actually Additions",
"summary": "As Actually Additions celebrates its fifth birthday, I break down what I like and dislike about it.", "summary": "As Actually Additions celebrates its fifth birthday, I break down what I like and dislike about it.",
"id": "actually_additions", "id": "actually_additions",
"cat": "Minecraft", "cat": ["Minecraft"],
"date": "5/10/2020", "date": "5/10/2020",
"discuss": "https://twitter.com/Ellpeck/status/1259600490377216002" "discuss": "https://twitter.com/Ellpeck/status/1259600490377216002"
}, },
@ -140,7 +140,7 @@
"name": "The Future of Actually Additions", "name": "The Future of Actually Additions",
"summary": "Not wanting to accept the fate of Actually Additions, someone has come to its rescue. 1.16, here we come?", "summary": "Not wanting to accept the fate of Actually Additions, someone has come to its rescue. 1.16, here we come?",
"id": "future_actually_additions", "id": "future_actually_additions",
"cat": "Minecraft", "cat": ["Minecraft", "Featured"],
"date": "11/23/2020", "date": "11/23/2020",
"discuss": "https://twitter.com/Ellpeck/status/1330938597785169925" "discuss": "https://twitter.com/Ellpeck/status/1330938597785169925"
}, },
@ -148,7 +148,7 @@
"name": "Your Minecraft Modding Questions, Answered", "name": "Your Minecraft Modding Questions, Answered",
"summary": "I asked yall to send me your modding and programming questions on Twitter and Discord, and in this post, I try to answer all of those.", "summary": "I asked yall to send me your modding and programming questions on Twitter and Discord, and in this post, I try to answer all of those.",
"id": "modding_ama", "id": "modding_ama",
"cat": "Minecraft", "cat": ["Minecraft", "Featured"],
"date": "3/21/2021", "date": "3/21/2021",
"discuss": "https://twitter.com/Ellpeck/status/1373660751060160512" "discuss": "https://twitter.com/Ellpeck/status/1373660751060160512"
} }

View file

@ -101,7 +101,7 @@
<div class="sellout"> <div class="sellout">
<iframe src="https://github.com/sponsors/Ellpeck/button" title="Sponsor Ellpeck" height="32" width="116" style="border: 0; margin-right: 10px;"></iframe> <iframe src="https://github.com/sponsors/Ellpeck/button" title="Sponsor Ellpeck" height="32" width="116" style="border: 0; margin-right: 10px;"></iframe>
<a href="https://www.patreon.com/bePatron?u=2494595" class="patreon-button" style="padding: 5px;"> <a href="https://www.patreon.com/bePatron?u=2494595" class="patreon-button" style="padding: 5px;">
<img src="../res/becomePatron.png" width="auto" height="34px" alt="Become a patron"> <img src="./res/becomePatron.png" width="auto" height="34px" alt="Become a patron">
</a> </a>
</div> </div>
</div> </div>
@ -237,6 +237,7 @@
<ul> <ul>
<li>A cookie named <code>dark</code> with the value <code>true</code> or <code>false</code> that stores if you have dark mode enabled</li> <li>A cookie named <code>dark</code> with the value <code>true</code> or <code>false</code> that stores if you have dark mode enabled</li>
<li>A cookie named <code>notification</code> with the value <code>true</code> or <code>false</code> that stores if you have already closed the cookie notification that displays at the top of the page</li> <li>A cookie named <code>notification</code> with the value <code>true</code> or <code>false</code> that stores if you have already closed the cookie notification that displays at the top of the page</li>
<li>A cookie named <code>category</code> that stores the category in the blog that you last selected</li>
</ul> </ul>
<p>Due to widgets and embeds, additional information will be stored by other sites. Please refer to those sites' privacy policies for more information:</p> <p>Due to widgets and embeds, additional information will be stored by other sites. Please refer to those sites' privacy policies for more information:</p>
<ul> <ul>

View file

@ -41,9 +41,9 @@ fs.readFile(`${folder}index.html`, function (_, html) {
document.querySelector('meta[property="og:description"]').setAttribute("content", post.summary); document.querySelector('meta[property="og:description"]').setAttribute("content", post.summary);
document.getElementById("nav-items").innerHTML = /*html*/ ` document.getElementById("nav-items").innerHTML = /*html*/ `
<a class="nav-item nav-link" href="/#blog">Back to Main Page</a> <a class="nav-item nav-link" href="../#blog">Back to Main Page</a>
${last ? /*html*/ `<a class="nav-item nav-link" href="/blog/${last.id}">Previous ${post.cat} Post</a>` : ""} ${last ? /*html*/ `<a class="nav-item nav-link" href="./${last.id}">Previous ${post.cat[0]} Post</a>` : ""}
${next ? /*html*/ `<a class="nav-item nav-link" href="/blog/${next.id}">Next ${post.cat} Post</a>` : ""} ${next ? /*html*/ `<a class="nav-item nav-link" href="./${next.id}">Next ${post.cat[0]} Post</a>` : ""}
`; `;
document.getElementById("main").innerHTML = /*html*/ ` document.getElementById("main").innerHTML = /*html*/ `
@ -70,13 +70,13 @@ fs.readFile(`${folder}index.html`, function (_, html) {
}); });
function getAdjacentPost(json, index, move) { function getAdjacentPost(json, index, move) {
let cat = json[index].cat; let cat = json[index].cat[0];
while (true) { while (true) {
index += move; index += move;
let post = json[index]; let post = json[index];
if (!post) if (!post)
break; break;
if (post.cat === cat && !post.archived) if (post.cat.includes(cat) && !post.archived)
return post; return post;
} }
} }

View file

@ -926,9 +926,9 @@
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
}, },
"y18n": { "y18n": {
"version": "4.0.0", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz",
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ=="
}, },
"yargs": { "yargs": {
"version": "14.2.2", "version": "14.2.2",

View file

@ -49,12 +49,14 @@ function createFeed(callback) {
content: html, content: html,
date: date, date: date,
published: date, published: date,
category: [{ category: post.cat.map(c => ({
name: post.cat name: c
}] }))
}); });
if (feed.categories.indexOf(post.cat) < 0) for (let cat of post.cat) {
feed.addCategory(post.cat); if (feed.categories.indexOf(cat) < 0)
feed.addCategory(cat);
}
if (index === 0) if (index === 0)
finalCallback(feed); finalCallback(feed);

View file

@ -9,12 +9,12 @@ $.ajax({
url: "blog/src/posts.json", url: "blog/src/posts.json",
cache: false, cache: false,
success: function (json) { success: function (json) {
populateBlog(json, "All"); populateBlog(json, getCookie("category") || "Featured");
forceToAnchor(); forceToAnchor();
} }
}); });
function populateBlog(json, cat) { function populateBlog(json, currCat) {
let archive = $('#blog-archive'); let archive = $('#blog-archive');
let list = $('#blog-list'); let list = $('#blog-list');
let cats = $('#blog-cats'); let cats = $('#blog-cats');
@ -22,22 +22,26 @@ function populateBlog(json, cat) {
list.html(""); list.html("");
cats.html(""); cats.html("");
addCatButton(json, cats, "All", cat); // force all and featured categories to be first
addCatButton(json, cats, "All", currCat);
addCatButton(json, cats, "Featured", currCat);
for (let i = json.length - 1; i >= 0; i--) { for (let i = json.length - 1; i >= 0; i--) {
let obj = json[i]; let post = json[i];
addCatButton(json, cats, obj.cat, cat); for (let cat of post.cat)
if (cat === "All" || obj.cat === cat) { addCatButton(json, cats, cat, currCat);
if (currCat === "All" || post.cat.includes(currCat)) {
let p = /*html*/ ` let p = /*html*/ `
<div class="card bg-light blog-entry rounded-0"> <div class="card bg-light blog-entry rounded-0">
<div class="card-body"> <div class="card-body">
<h4 class="card-title blog-title"><a class="blog-button" href="/blog/${obj.id}">${obj.name}</a></h4> <h4 class="card-title blog-title"><a class="blog-button" href="./blog/${post.id}">${post.name}</a></h4>
<div class="card-text blog-summary">${obj.summary}</div> <div class="card-text blog-summary">${post.summary}</div>
<span class="text-muted project-status">${obj.date}</span> <span class="text-muted project-status">${post.date}</span>
<span class="text-muted blog-cat">${obj.cat}</span> <span class="text-muted blog-cat">${post.cat.join(", ")}</span>
</div> </div>
</div> </div>
`; `;
if (obj.archived) { if (post.archived) {
archive.append(p); archive.append(p);
} else { } else {
list.append(p); list.append(p);
@ -46,7 +50,7 @@ function populateBlog(json, cat) {
} }
if (!archive.html()) if (!archive.html())
archive.html(`<em>There are no archived ${cat} posts.</em>`); archive.html(`<em>There are no archived ${currCat} posts.</em>`);
} }
function addCatButton(json, cats, cat, currCat) { function addCatButton(json, cats, cat, currCat) {
@ -55,6 +59,7 @@ function addCatButton(json, cats, cat, currCat) {
cats.append( /*html*/ `<button type="button" class="btn btn-link blog-cat-button" id=${catAnchor} ${cat === currCat ? "disabled" : ""}>${cat}</button>`); cats.append( /*html*/ `<button type="button" class="btn btn-link blog-cat-button" id=${catAnchor} ${cat === currCat ? "disabled" : ""}>${cat}</button>`);
$(`#${catAnchor}`).on('click', function () { $(`#${catAnchor}`).on('click', function () {
populateBlog(json, cat); populateBlog(json, cat);
setCookie("category", cat, 365);
}); });
} }
} }

View file

@ -1,10 +1,6 @@
function getCookie(key) { function getCookie(key) {
let c = document.cookie; let match = new RegExp(`${key}=([^;]+);?`, "g").exec(document.cookie);
if (!c) return match ? match[1] : undefined;
return undefined;
let start = c.indexOf(`${key}=`) + key.length + 1;
let end = c.indexOf(";", start);
return c.substring(start, end < 0 ? c.length : end);
} }
function setCookie(key, value, days) { function setCookie(key, value, days) {