From c477334cad3026b1e2d41b9e3dbaff332f8472b4 Mon Sep 17 00:00:00 2001 From: Thomas Schoffelen Date: Fri, 2 Jun 2023 14:54:15 +0100 Subject: [PATCH] Fix filtering. --- lib/blog.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/blog.js b/lib/blog.js index a2c680b..1c8e069 100644 --- a/lib/blog.js +++ b/lib/blog.js @@ -53,19 +53,21 @@ export const getPosts = cache(async () => { return posts .filter((post) => { - const classifiedDate = new Date(post.attributes?.date || post.createdAt) + if (!post.attributes?.url) return true; + + const normalizedDate = new Date(post.attributes?.date || post.createdAt) .toISOString() - .substring(0, 7); - return !( - post.attributes?.url && - posts.some( - (p) => - p.title === post.title && - classifiedDate === - new Date(p.attributes?.date || p.createdAt) - .toISOString() - .substring(0, 7) - ) + .substring(0, 6); + + return !posts.some( + (p) => + p.title === post.title && + p.id !== post.id && + p.html && + normalizedDate === + new Date(p.attributes?.date || p.createdAt) + .toISOString() + .substring(0, 6) ); }) .map(formatPost)