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

18
src/_data/analytics.js Normal file
View file

@ -0,0 +1,18 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const API_KEY_PLAUSIBLE = process.env.API_KEY_PLAUSIBLE
const url =
'https://plausible.io/api/v1/stats/breakdown?site_id=coryd.dev&period=6mo&property=event:page&limit=30'
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
fetchOptions: {
headers: {
Authorization: `Bearer ${API_KEY_PLAUSIBLE}`,
},
},
}).catch()
const pages = await res
return pages.results.filter((p) => p.page.includes('posts')).splice(0, 5)
}