blog post and other fixes/additions #124

Merged
freakoverse merged 55 commits from staging into master 2024-11-14 18:26:41 +00:00
Showing only changes of commit 91830a539a - Show all commits

View File

@ -361,15 +361,12 @@ const DisplayLatestBlogs = () => {
const latestFilter: NDKFilter = {
authors: blogHexkeys,
kinds: [kinds.LongFormArticle],
limit: 4
limit: PROFILE_BLOG_FILTER_LIMIT
}
// Filter by NSFW tag
if (filterOptions.nsfw === NSFWFilter.Only_NSFW) {
latestFilter['#L'] = ['content-warning']
} else if (filterOptions.nsfw === NSFWFilter.Hide_NSFW) {
// Up the limit in case we fetch multiple NSFW blogs
latestFilter.limit = PROFILE_BLOG_FILTER_LIMIT
}
const results = await Promise.allSettled([
@ -377,26 +374,36 @@ const DisplayLatestBlogs = () => {
fetchEvents(latestFilter)
])
const events: NDKEvent[] = []
const events: Partial<BlogCardDetails>[] = []
// Get featured blogs posts result
results.forEach((r) => {
// Add events from both promises to the array
if (r.status === 'fulfilled' && r.value) {
events.push(...r.value)
events.push(
...r.value
.map(extractBlogCardDetails) // Extract the blog card details
.sort(
// Sort each result by published_at in descending order
// We can't sort everything at once we'd lose prefered
(a, b) =>
a.published_at && b.published_at
? b.published_at - a.published_at
: 0
)
)
}
})
// Remove duplicates
const unique = Array.from(
events
.filter((b) => b.id)
.reduce((map, obj) => {
map.set(obj.id, obj)
map.set(obj.id!, obj)
return map
}, new Map())
}, new Map<string, Partial<BlogCardDetails>>())
.values()
)
.map(extractBlogCardDetails)
.filter(
).filter(
(b) => !(b.nsfw && filterOptions.nsfw === NSFWFilter.Hide_NSFW)
)