Merge branch 'main' of git@github.com:cdransf/coryd.dev.git
This commit is contained in:
commit
3f0549a08c
13 changed files with 149 additions and 1200 deletions
|
@ -1,5 +1,6 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
import { DateTime } from 'luxon'
|
||||
import { sanitizeMediaString, parseCountryField } from '../../config/utilities/index.js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
|
@ -15,7 +16,7 @@ export default async function () {
|
|||
image,
|
||||
release_date,
|
||||
release_link,
|
||||
artists (name_string, genre, mbid)
|
||||
artists (name_string, genre, mbid, country)
|
||||
`)
|
||||
.gt('release_date', today)
|
||||
|
||||
|
@ -30,6 +31,7 @@ export default async function () {
|
|||
title: album['name'],
|
||||
date: DateTime.fromISO(album['release_date']).toLocaleString(DateTime.DATE_FULL),
|
||||
url: album['release_link'],
|
||||
artist_url: `https://coryd.dev/music/artists/${sanitizeMediaString(album['artists']['name_string'])}-${sanitizeMediaString(parseCountryField(album['artists']['country']))}`,
|
||||
genre: album['artists']['genre'],
|
||||
mbid: album['artists']['mbid'],
|
||||
timestamp: DateTime.fromISO(album['release_date']).toSeconds()
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
import { createClient } from '@supabase/supabase-js';
|
||||
import { DateTime } from 'luxon'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
const aggregateData = (data) => {
|
||||
const aggregation = {}
|
||||
data.forEach(item => {
|
||||
const key = item['artist_name']
|
||||
if (!aggregation[key]) {
|
||||
aggregation[key] = {
|
||||
name: item['artist_name'],
|
||||
genre: item['artists']['genre'],
|
||||
mbid: item['artists']['mbid'],
|
||||
plays: 0
|
||||
}
|
||||
}
|
||||
aggregation[key].plays++
|
||||
})
|
||||
return Object.values(aggregation).sort((a, b) => b.plays - a.plays).slice(0, 8)
|
||||
}
|
||||
|
||||
const formatData = (data) => {
|
||||
let content = 'My top artists for the week: '
|
||||
let description = '<p>My top artists for the last week:</p><ul>'
|
||||
data.forEach((artist, index) => {
|
||||
content += `${artist['name']} @ ${artist['plays']} play${parseInt(artist['plays']) > 1 ? 's' : ''}`
|
||||
description+= `<li>${artist['name']} @ ${artist['plays']} • ${artist['genre']}</li>`
|
||||
if (index !== data.length - 1) content += ', '
|
||||
})
|
||||
description += '</ul>'
|
||||
return { content, description }
|
||||
}
|
||||
|
||||
export default async function() {
|
||||
try {
|
||||
const now = DateTime.now();
|
||||
const startOfWeek = now.minus({ days: 7 }).startOf('day')
|
||||
const endOfWeek = now.endOf('day')
|
||||
const startOfWeekSeconds = startOfWeek.toSeconds()
|
||||
const endOfWeekSeconds = endOfWeek.toSeconds()
|
||||
const weekNumber = now.toFormat('kkkk-WW')
|
||||
let { data: recentCharts } = await supabase
|
||||
.from('weekly_charts')
|
||||
.select('*')
|
||||
.order('date', { ascending: false })
|
||||
.limit(10);
|
||||
|
||||
if (now.weekday !== 1) return recentCharts.map(chart => {
|
||||
const formattedData = formatData(JSON.parse(chart['data']))
|
||||
return {
|
||||
title: formattedData['content'],
|
||||
description: formattedData['description'],
|
||||
url: `https://coryd.dev/music?ts=${chart['week']}`,
|
||||
date: chart['date']
|
||||
}
|
||||
})
|
||||
|
||||
if (recentCharts.some(chart => chart['week'] === weekNumber)) {
|
||||
return recentCharts.map(chart => {
|
||||
const formattedData = formatData(JSON.parse(chart['data']))
|
||||
return {
|
||||
title: formattedData['content'],
|
||||
description: formattedData['description'],
|
||||
url: `https://coryd.dev/music?ts=${chart['week']}`,
|
||||
date: chart['date']
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let { data: listens, error } = await supabase
|
||||
.from('listens')
|
||||
.select(`
|
||||
listened_at,
|
||||
track_name,
|
||||
artist_name,
|
||||
artists(mbid, genre)
|
||||
`)
|
||||
.gte('listened_at', startOfWeekSeconds)
|
||||
.lte('listened_at', endOfWeekSeconds)
|
||||
|
||||
if (error) throw error
|
||||
|
||||
const aggregatedData = aggregateData(listens)
|
||||
const artistNames = aggregatedData.map(artist => artist.name)
|
||||
let { data: artistsData, error: artistsError } = await supabase
|
||||
.from('artists')
|
||||
.select('name_string, genre, mbid')
|
||||
.in('name_string', artistNames)
|
||||
|
||||
if (artistsError) throw artistsError
|
||||
|
||||
const topArtists = aggregatedData.map(artist => {
|
||||
return {
|
||||
name: artist.name,
|
||||
genre: artist?.genre || '',
|
||||
plays: artist.plays,
|
||||
mbid: artist?.mbid || ''
|
||||
}
|
||||
})
|
||||
|
||||
const { error: insertError } = await supabase
|
||||
.from('weekly_charts')
|
||||
.insert([{ week: weekNumber, date: now.toISODate(), data: JSON.stringify(topArtists) }])
|
||||
if (insertError) throw insertError
|
||||
const formattedData = formatData(topArtists)
|
||||
const recentChartData = recentCharts.map(chart => {
|
||||
const formattedData = formatData(JSON.parse(chart['data']))
|
||||
return {
|
||||
title: formattedData['content'],
|
||||
description: formattedData['description'],
|
||||
url: `https://coryd.dev/now?ts=${chart['week']}#artists`,
|
||||
date: chart['date']
|
||||
}
|
||||
})
|
||||
return [
|
||||
{
|
||||
title: formattedData['content'],
|
||||
description: formattedData['description'],
|
||||
url: `https://coryd.dev/now?ts=${weekNumber}#artists`,
|
||||
date: now.toISODate()
|
||||
},
|
||||
...recentChartData
|
||||
]
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message)
|
||||
}
|
||||
}
|
|
@ -11,10 +11,10 @@
|
|||
{{ album.title }}
|
||||
</a>
|
||||
<span> by </span>
|
||||
<a href="https://musicbrainz.org/artist/{{ album.mbid }}">
|
||||
<a href="{{ album.artist_url }}">
|
||||
{{ album.artist }}
|
||||
</a>
|
||||
<span> • {{ album.genre }}</span>
|
||||
<span> • <a href="https://coryd.dev/music/genres/{{ album.genre | slugify | downcase }}">{{ album.genre }}</a></span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -144,6 +144,10 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
& .footnotes {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 768px) {
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
layout: null
|
||||
eleventyExcludeFromCollections: true
|
||||
permalink: /feeds/weekly-artist-chart
|
||||
---
|
||||
{% render "partials/feeds/rss.liquid"
|
||||
permalink:"/feeds/weekly-artist-chart"
|
||||
title:"Weekly artist chart • Cory Dransfeldt"
|
||||
description:"The top 8 artists I've listened to this week."
|
||||
data:weeklyArtistChart
|
||||
updated:weeklyArtistChart[0].date
|
||||
site:site
|
||||
%}
|
|
@ -13,5 +13,4 @@ These are web feeds, also known as [RSS](https://en.wikipedia.org/wiki/RSS) or [
|
|||
- Links ([RSS](https://feedpress.me/coryd-links) • [JSON](https://feedpress.me/coryd-links.json)): links I've liked.
|
||||
- Books ([RSS](https://feedpress.me/coryd-books) • [JSON](https://feedpress.me/coryd-books.json)): books I'm currently reading.
|
||||
- Movies ([RSS](https://feedpress.me/coryd-movies) • [JSON](https://feedpress.me/coryd-books.json)): movies I've watched recently.
|
||||
- Artist charts ([RSS](https://feedpress.me/coryd-artist-charts) • [JSON](https://feedpress.me/coryd-artist-charts.json)): charts of the artists I've listened to each week.
|
||||
- All ([RSS](https://feedpress.me/coryd-all) • [JSON](https://feedpress.me/coryd-all.json)): all of the posts and activity from my site.
|
|
@ -13,7 +13,6 @@ schema: music
|
|||
<p>This is everything I've been listening to recently — it's collected in a database as I listen to it and displayed here. <a href="https://coryd.dev/posts/2024/improving-my-self-hosted-scrobbling-implementation/">You can read more about the technical details, if you'd like.</a></p>
|
||||
<p>I mostly listen to {{ genres | sortByPlaysDescending: "total_plays" | genreStrings: "name" | mediaLinks: "genre", 5 }}. This week I've listened to <strong class="highlight-text">{{ music.week.artists.size }} artists</strong>, <strong class="highlight-text">{{ music.week.albums.size }} albums</strong> and <strong class="highlight-text">{{ music.week.totalTracks }} tracks</strong>.</p>
|
||||
{% render "partials/widgets/now-playing.liquid" %}
|
||||
{% render "partials/banners/rss.liquid", url: "https://feedpress.me/coryd-artist-charts", text: "I also have a feed of weekly artist charts I generate from this data" %}
|
||||
<hr class="large-spacing" />
|
||||
<div class="section-header-wrapper">
|
||||
<h2 id="artists" class="section-header no-top-margin flex-centered">
|
||||
|
|
Reference in a new issue