From 7506a1545c8c8b1a1a45f5d8020602e97ec221e4 Mon Sep 17 00:00:00 2001 From: tomsterBG <117642342+tomsterBG@users.noreply.github.com> Date: Tue, 6 May 2025 18:57:59 +0300 Subject: [PATCH 1/2] improve readability of posts.md A tiny tweak to make it more obvious what the if site.posts[0] is doing. --- posts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posts.md b/posts.md index a9ae91d..b11a8fc 100644 --- a/posts.md +++ b/posts.md @@ -1,10 +1,10 @@ ---- + --- layout: page title: posts | brainfucksec ---
- {% if site.posts[0] %} + {% if site.posts.size > 0 %} {% capture currentyear %}{{ 'now' | date: "%Y" }}{% endcapture %} {% capture firstpostyear %}{{ site.posts[0].date | date: '%Y' }}{% endcapture %} From 9c897bc98986ed4e7fc3d82bff6924a261a9181a Mon Sep 17 00:00:00 2001 From: tomsterBG <117642342+tomsterBG@users.noreply.github.com> Date: Tue, 6 May 2025 20:09:43 +0300 Subject: [PATCH 2/2] Update posts.md Refactored the code so it's easier to filter posts. It was necessary to eliminate post.next because apparently it doesn't work when you filter a table. In lua we have deepcopy, in liquidjs... idk, but this is my solution. Also when there are no posts it prints "No posts to display" which is very useful if you have a hidden system like the one i decided to add. The filtered_posts variable comes preconfigured for every post that doesn't have the hidden = true variable in its frontmatter, for more info on this you can check out the main branch of my fork to see how the whole hidden thing works. I just want to make future forks more easily capable of adding this modification. --- posts.md | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/posts.md b/posts.md index b11a8fc..de2c23d 100644 --- a/posts.md +++ b/posts.md @@ -4,35 +4,38 @@ title: posts | brainfucksec ---
- {% if site.posts.size > 0 %} + {% assign filtered_posts = site.posts | where_exp: "post", "post.hidden != true" | sort: "date" | reverse %} + {% if filtered_posts.size > 0 %} {% capture currentyear %}{{ 'now' | date: "%Y" }}{% endcapture %} - {% capture firstpostyear %}{{ site.posts[0].date | date: '%Y' }}{% endcapture %} - {% if currentyear == firstpostyear %} + {% capture postyear %}{{ filtered_posts[0].date | date: '%Y' }}{% endcapture %} + {% if currentyear == postyear %}

This year's posts

{% else %} -

{{ firstpostyear }}

+

{{ postyear }}

{% endif %} - {%for post in site.posts %} - {% unless post.next %} -