From ae9d23b5078eae7861b367b6cf42a02ea7313cda Mon Sep 17 00:00:00 2001 From: Kerby Martino Date: Mon, 5 May 2025 12:03:24 +0800 Subject: [PATCH] feat: add filter and sort functionality to post list --- _includes/post_list.liquid | 186 +++++++++++-------------------------- pages/frustration.md | 7 ++ pages/weird.md | 7 ++ pages/win.md | 7 ++ 4 files changed, 76 insertions(+), 131 deletions(-) create mode 100644 pages/frustration.md create mode 100644 pages/weird.md create mode 100644 pages/win.md diff --git a/_includes/post_list.liquid b/_includes/post_list.liquid index 9afd036..a8b8841 100644 --- a/_includes/post_list.liquid +++ b/_includes/post_list.liquid @@ -3,47 +3,61 @@

Quick Tips: Keep it brief, keep it real. Share your desk moments, finds, or frustrations. Upvote what resonates!

+{% assign filter_type = page.filter_type | default: 'all' %} +{% assign sort_by = page.sort_by | default: 'new' %} +
- - - - + + + All + + + Win + Wins + + + Frustration + Frustrations + + + Weird + Weird +
- +
- +
- +
- {% assign sorted_posts = site.posts | sort: 'date' | reverse %} - {% for post in sorted_posts %} -
-
-
-
+ {% assign posts = site.posts %} + + {% if filter_type != 'all' %} + {% assign posts = posts | where: 'type', filter_type %} + {% endif %} + + {% assign posts = posts | sort: 'date' | reverse %} + + {% if posts == empty %} +
+

No results found for this filter.

+
+ {% else %} + {% for post in posts %} +
+
+

@@ -58,15 +72,15 @@

- - {{ post.upvotes }} - - - REPLY - - - {{ post.comments_count }} - + + {{ post.upvotes }} + + + REPLY + + + {{ post.comments_count }} +
{{ post.author }} @@ -74,104 +88,14 @@
-
-
-
-
- {% endfor %} +
+
+
+ {% endfor %} + {% endif %}
- +
- - diff --git a/pages/frustration.md b/pages/frustration.md new file mode 100644 index 0000000..bd5d225 --- /dev/null +++ b/pages/frustration.md @@ -0,0 +1,7 @@ +--- +layout: default +title: Frustrations +permalink: /frustration/ +filter_type: frustration +--- +{% include post_list.liquid %} diff --git a/pages/weird.md b/pages/weird.md new file mode 100644 index 0000000..c7107c8 --- /dev/null +++ b/pages/weird.md @@ -0,0 +1,7 @@ +--- +layout: default +title: Weird +permalink: /weird/ +filter_type: weird +--- +{% include post_list.liquid %} diff --git a/pages/win.md b/pages/win.md new file mode 100644 index 0000000..375b268 --- /dev/null +++ b/pages/win.md @@ -0,0 +1,7 @@ +--- +layout: default +title: Wins +permalink: /win/ +filter_type: win +--- +{% include post_list.liquid %}