chore: cut widget over

This commit is contained in:
Cory Dransfeldt 2023-08-22 14:18:10 -07:00
parent 96a604669b
commit 14e1945ba4
No known key found for this signature in database
4 changed files with 9 additions and 9 deletions

2
.env
View file

@ -1,5 +1,5 @@
API_KEY_LASTFM=
API_KEY_PLAUSIBLE=
API_KEY_FATHOM=
API_KEY_TRAKT=
API_KEY_WEBMENTIONS_CORYD_DEV=
API_TOKEN_READWISE=

View file

@ -28,10 +28,10 @@ module.exports = {
getPopularPosts: (posts, analytics) => {
return posts
.filter((post) => {
if (analytics.find((p) => p.page === post.url)) return true
if (analytics.find((p) => p.pathname === post.url)) return true
})
.sort((a, b) => {
const visitors = (page) => analytics.filter((p) => p.page === page.url).pop().visitors
const visitors = (page) => analytics.filter((p) => p.pathname === page.url).pop().visitors
return visitors(b) - visitors(a)
})
},

View file

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

View file

@ -5,7 +5,7 @@
<div class="ml-1">Popular posts</div>
</h2>
<ul class="list-inside list-disc pl-5 md:pl-10">
{% for post in posts %}
{% for post in posts limit: 5 %}
<li class="mt-1.5 mb-2">
<a href="{{post.url}}" title="{{ post.data.title | escape}}">
{{ post.data.title }}
@ -13,4 +13,4 @@
</li>
{% endfor %}
</ul>
</div>
</div>