blog post and other fixes/additions #124
@ -361,15 +361,12 @@ const DisplayLatestBlogs = () => {
|
|||||||
const latestFilter: NDKFilter = {
|
const latestFilter: NDKFilter = {
|
||||||
authors: blogHexkeys,
|
authors: blogHexkeys,
|
||||||
kinds: [kinds.LongFormArticle],
|
kinds: [kinds.LongFormArticle],
|
||||||
limit: 4
|
limit: PROFILE_BLOG_FILTER_LIMIT
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter by NSFW tag
|
// Filter by NSFW tag
|
||||||
if (filterOptions.nsfw === NSFWFilter.Only_NSFW) {
|
if (filterOptions.nsfw === NSFWFilter.Only_NSFW) {
|
||||||
latestFilter['#L'] = ['content-warning']
|
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([
|
const results = await Promise.allSettled([
|
||||||
@ -377,26 +374,36 @@ const DisplayLatestBlogs = () => {
|
|||||||
fetchEvents(latestFilter)
|
fetchEvents(latestFilter)
|
||||||
])
|
])
|
||||||
|
|
||||||
const events: NDKEvent[] = []
|
const events: Partial<BlogCardDetails>[] = []
|
||||||
// Get featured blogs posts result
|
// Get featured blogs posts result
|
||||||
results.forEach((r) => {
|
results.forEach((r) => {
|
||||||
// Add events from both promises to the array
|
// Add events from both promises to the array
|
||||||
if (r.status === 'fulfilled' && r.value) {
|
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
|
// Remove duplicates
|
||||||
const unique = Array.from(
|
const unique = Array.from(
|
||||||
events
|
events
|
||||||
|
.filter((b) => b.id)
|
||||||
.reduce((map, obj) => {
|
.reduce((map, obj) => {
|
||||||
map.set(obj.id, obj)
|
map.set(obj.id!, obj)
|
||||||
return map
|
return map
|
||||||
}, new Map())
|
}, new Map<string, Partial<BlogCardDetails>>())
|
||||||
.values()
|
.values()
|
||||||
)
|
).filter(
|
||||||
.map(extractBlogCardDetails)
|
|
||||||
.filter(
|
|
||||||
(b) => !(b.nsfw && filterOptions.nsfw === NSFWFilter.Hide_NSFW)
|
(b) => !(b.nsfw && filterOptions.nsfw === NSFWFilter.Hide_NSFW)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user