Skip to content

Commit

Permalink
Fix filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen committed Jun 2, 2023
1 parent bd8c446 commit c477334
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c477334

Please sign in to comment.