added a featured category to the blog
Web/pipeline/head This commit looks good Details

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",
"summary": "The first post and how I created it",
"id": "blogs_are_cool",
"cat": "Miscellaneous",
"cat": ["Miscellaneous"],
"date": "2/17/2019",
"discuss": "https://twitter.com/Ellpeck/status/1096937184601538566",
"archived": true
@ -11,7 +11,7 @@
"name": "Why You Should Mod Minecraft",
"summary": "About what makes Minecraft modding great and why you should probably try it if you enjoy programming",
"id": "why_you_should_mod_minecraft",
"cat": "Minecraft",
"cat": ["Minecraft", "Programming"],
"date": "2/17/2019",
"discuss": "https://twitter.com/Ellpeck/status/1097177774337462272"
},
@ -19,7 +19,7 @@
"name": "Kindling the Reading Flame",
"summary": "About the Kindle, Harry Potter and what I like and dislike about them",
"id": "reading",
"cat": "Miscellaneous",
"cat": ["Miscellaneous"],
"date": "3/22/2019",
"discuss": "https://twitter.com/Ellpeck/status/1109102077911973888"
},
@ -27,7 +27,7 @@
"name": "Small Projects",
"summary": "Why creating a small, unplanned project is sometimes good for you",
"id": "small_projects",
"cat": "Programming",
"cat": ["Programming"],
"date": "5/1/2019",
"discuss": "https://twitter.com/Ellpeck/status/1123651624201871360"
},
@ -35,7 +35,7 @@
"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",
"id": "cross_platform_trainwreck",
"cat": "Programming",
"cat": ["Programming"],
"date": "7/6/2019",
"discuss": "https://twitter.com/Ellpeck/status/1147502654236573697",
"archived": true
@ -44,7 +44,7 @@
"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",
"id": "big_projects",
"cat": "Programming",
"cat": ["Programming"],
"date": "9/15/2019",
"discuss": "https://twitter.com/Ellpeck/status/1173247686654517249"
},
@ -52,7 +52,7 @@
"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",
"id": "rock_bottom_mod",
"cat": "Programming",
"cat": ["Programming"],
"date": "10/3/2019",
"discuss": "https://twitter.com/Ellpeck/status/1180092634410487808"
},
@ -60,7 +60,7 @@
"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.",
"id": "java_1",
"cat": "Java Tutorials",
"cat": ["Java Tutorials", "Featured"],
"date": "10/10/2019",
"discuss": "https://twitter.com/Ellpeck/status/1182080078827737088"
},
@ -68,7 +68,7 @@
"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.",
"id": "java_2",
"cat": "Java Tutorials",
"cat": ["Java Tutorials"],
"date": "10/10/2019",
"discuss": "https://twitter.com/Ellpeck/status/1182354544707198976"
},
@ -76,7 +76,7 @@
"name": "Java Tutorial, Part 3: (Static) Methods",
"summary": "In this Java tutorial for beginners, we cover what (static) methods, parameters and return types are.",
"id": "java_3",
"cat": "Java Tutorials",
"cat": ["Java Tutorials"],
"date": "10/11/2019",
"discuss": "https://twitter.com/Ellpeck/status/1182775985885847558"
},
@ -84,7 +84,7 @@
"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.",
"id": "java_4",
"cat": "Java Tutorials",
"cat": ["Java Tutorials"],
"date": "10/14/2019",
"discuss": "https://twitter.com/Ellpeck/status/1183857460660101133"
},
@ -92,7 +92,7 @@
"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.",
"id": "java_5",
"cat": "Java Tutorials",
"cat": ["Java Tutorials"],
"date": "10/17/2019",
"discuss": "https://twitter.com/Ellpeck/status/1184894859133509632"
},
@ -100,7 +100,7 @@
"name": "Lows",
"summary": "About depression and what it feels like when I don't know what to do with myself",
"id": "lows",
"cat": "Miscellaneous",
"cat": ["Miscellaneous"],
"date": "10/20/2019",
"discuss": "https://twitter.com/Ellpeck/status/1186028260838334471",
"archived": true
@ -109,7 +109,7 @@
"name": "Java Tutorial, Part 6: Inheritance",
"summary": "In this Java tutorial for beginners, we cover classes extending other classes and the instanceof keyword.",
"id": "java_6",
"cat": "Java Tutorials",
"cat": ["Java Tutorials"],
"date": "10/31/2019",
"discuss": "https://twitter.com/Ellpeck/status/1189904487722487809"
},
@ -117,7 +117,7 @@
"name": "Java Tutorial, Part 7: Overriding Methods",
"summary": "In this Java tutorial for beginners, we cover overriding methods, calling superclass methods and toString().",
"id": "java_7",
"cat": "Java Tutorials",
"cat": ["Java Tutorials"],
"date": "11/26/2019",
"discuss": "https://twitter.com/Ellpeck/status/1199339701640945664"
},
@ -125,14 +125,14 @@
"name": "But Do You Really Care?",
"summary": "On taking a break from social media",
"id": "but_do_you_really_care",
"cat": "Miscellaneous",
"cat": ["Miscellaneous"],
"date": "5/6/2020"
},
{
"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.",
"id": "actually_additions",
"cat": "Minecraft",
"cat": ["Minecraft"],
"date": "5/10/2020",
"discuss": "https://twitter.com/Ellpeck/status/1259600490377216002"
},
@ -140,7 +140,7 @@
"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?",
"id": "future_actually_additions",
"cat": "Minecraft",
"cat": ["Minecraft", "Featured"],
"date": "11/23/2020",
"discuss": "https://twitter.com/Ellpeck/status/1330938597785169925"
},
@ -148,7 +148,7 @@
"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.",
"id": "modding_ama",
"cat": "Minecraft",
"cat": ["Minecraft", "Featured"],
"date": "3/21/2021",
"discuss": "https://twitter.com/Ellpeck/status/1373660751060160512"
}

View File

@ -101,7 +101,7 @@
<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>
<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>
</div>
</div>
@ -237,6 +237,7 @@
<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>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>
<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>

View File

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

View File

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

View File

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

View File

@ -9,12 +9,12 @@ $.ajax({
url: "blog/src/posts.json",
cache: false,
success: function (json) {
populateBlog(json, "All");
populateBlog(json, getCookie("category") || "Featured");
forceToAnchor();
}
});
function populateBlog(json, cat) {
function populateBlog(json, currCat) {
let archive = $('#blog-archive');
let list = $('#blog-list');
let cats = $('#blog-cats');
@ -22,22 +22,26 @@ function populateBlog(json, cat) {
list.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--) {
let obj = json[i];
addCatButton(json, cats, obj.cat, cat);
if (cat === "All" || obj.cat === cat) {
let post = json[i];
for (let cat of post.cat)
addCatButton(json, cats, cat, currCat);
if (currCat === "All" || post.cat.includes(currCat)) {
let p = /*html*/ `
<div class="card bg-light blog-entry rounded-0">
<div class="card-body">
<h4 class="card-title blog-title"><a class="blog-button" href="/blog/${obj.id}">${obj.name}</a></h4>
<div class="card-text blog-summary">${obj.summary}</div>
<span class="text-muted project-status">${obj.date}</span>
<span class="text-muted blog-cat">${obj.cat}</span>
<h4 class="card-title blog-title"><a class="blog-button" href="./blog/${post.id}">${post.name}</a></h4>
<div class="card-text blog-summary">${post.summary}</div>
<span class="text-muted project-status">${post.date}</span>
<span class="text-muted blog-cat">${post.cat.join(", ")}</span>
</div>
</div>
`;
if (obj.archived) {
if (post.archived) {
archive.append(p);
} else {
list.append(p);
@ -46,7 +50,7 @@ function populateBlog(json, cat) {
}
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) {
@ -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>`);
$(`#${catAnchor}`).on('click', function () {
populateBlog(json, cat);
setCookie("category", cat, 365);
});
}
}

View File

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