diff --git a/config/filters.js b/config/filters.js index 8a4da986..e76a472f 100644 --- a/config/filters.js +++ b/config/filters.js @@ -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) }) }, diff --git a/src/_data/analytics.js b/src/_data/analytics.js index d97d911c..ab865513 100644 --- a/src/_data/analytics.js +++ b/src/_data/analytics.js @@ -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) }