feat: popular posts

This commit is contained in:
Cory Dransfeldt 2023-07-05 14:29:55 -07:00
parent 0479bce1f4
commit bd6783c5a0
No known key found for this signature in database
8 changed files with 75 additions and 27 deletions

View file

@ -15,6 +15,16 @@ module.exports = {
if (image && image !== '') return image
return '/assets/img/social-card.webp'
},
getPopularPosts: (posts, analytics) => {
return posts
.filter((post) => {
if (analytics.find((p) => p.page === post.url)) return true
})
.sort((a, b) => {
const visitors = (page) => analytics.filter((p) => p.page === page.url)[0].visitors
return visitors(b) - visitors(a)
})
},
webmentionsByUrl: (webmentions, url) => {
const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of']