fix: popular posts sort
This commit is contained in:
parent
8b61b7783b
commit
008a0393c8
2 changed files with 19 additions and 2 deletions
|
@ -31,7 +31,7 @@ module.exports = {
|
|||
if (analytics.find((p) => p.url.includes(post.url))) return true
|
||||
})
|
||||
.sort((a, b) => {
|
||||
const visitors = (page) => analytics.filter((p) => p.url.includes(page.url)).pop().value
|
||||
const visitors = (page) => analytics.filter((p) => p.url.includes(page.url)).pop().rank
|
||||
return visitors(b) - visitors(a)
|
||||
})
|
||||
},
|
||||
|
|
|
@ -10,5 +10,22 @@ module.exports = async function () {
|
|||
}).catch()
|
||||
const data = await res
|
||||
const pages = data[0].dates[0].items
|
||||
return pages.filter((p) => p.url.includes('posts'))
|
||||
.filter((p) => p.url.includes('posts'))
|
||||
.filter((p) => !p.url.includes('/null'))
|
||||
.map((page) => {
|
||||
return {
|
||||
title: page.title,
|
||||
rank: parseInt(page.value),
|
||||
url: page.url.split('?')[0],
|
||||
}
|
||||
})
|
||||
const postsObj = {}
|
||||
pages.forEach((page) => {
|
||||
if (postsObj[page.url]) {
|
||||
postsObj[page.url].rank += postsObj[page.url].rank
|
||||
} else {
|
||||
postsObj[page.url] = page
|
||||
}
|
||||
})
|
||||
return Object.values(postsObj)
|
||||
}
|
||||
|
|
Reference in a new issue