From f2be875272117e8f1464d5b72c8b56313e04fe77 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Mon, 27 May 2024 11:06:08 -0700 Subject: [PATCH] chore: drop chart posts --- config/collections/index.js | 4 +- package-lock.json | 10 +-- package.json | 2 +- src/_data/weeklyArtistChart.js | 130 --------------------------- src/feeds/weekly-artist-chart.liquid | 13 --- src/pages/main/feeds.md | 1 - src/pages/main/music/index.html | 1 - 7 files changed, 7 insertions(+), 154 deletions(-) delete mode 100644 src/_data/weeklyArtistChart.js delete mode 100644 src/feeds/weekly-artist-chart.liquid diff --git a/config/collections/index.js b/config/collections/index.js index a8610e5d..45a1a7cd 100644 --- a/config/collections/index.js +++ b/config/collections/index.js @@ -37,8 +37,7 @@ export const allContent = (collection) => { const { collections: { posts, links }, books, - movies: { movies }, - weeklyArtistChart + movies: { movies } } = data const parseDate = (date) => { if (!date) return null @@ -76,7 +75,6 @@ export const allContent = (collection) => { addContent(links, '🔗', item => item.data.title, item => item.data.date) addContent(books.filter(book => book.status === 'finished'), '📖', item => `${item.title}${item.rating ? ' (' + item.rating + ')' : ''}`, item => item.date) addContent(movies, '🎥', item => `${item.title}${item.rating ? ' (' + item.rating + ')' : ''}`, item => item.lastWatched) - addContent(weeklyArtistChart, '🎧', item => item.title, item => item.date) return aggregateContent.sort((a, b) => { const dateA = a.date ? DateTime.fromISO(a.date) : DateTime.fromMillis(0) diff --git a/package-lock.json b/package-lock.json index 1ad45a14..06ec2532 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "17.4.9", + "version": "17.4.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "17.4.9", + "version": "17.4.10", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.2.3", @@ -5817,9 +5817,9 @@ } }, "node_modules/sax": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz", - "integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.0.tgz", + "integrity": "sha512-G3nn4N8SRaR9NsCqEUHfTlfTM/Fgza1yfb8JP2CEmzYuHtHWza5Uf+g7nuUQq96prwu0GiGyPgDw752+j4fzQQ==", "dev": true }, "node_modules/section-matter": { diff --git a/package.json b/package.json index e3b71d44..f2d6e223 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "17.4.9", + "version": "17.4.10", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/src/_data/weeklyArtistChart.js b/src/_data/weeklyArtistChart.js deleted file mode 100644 index c57888ed..00000000 --- a/src/_data/weeklyArtistChart.js +++ /dev/null @@ -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 = '

My top artists for the last week:

' - 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']}#artists`, - 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 { 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/music?ts=${chart['week']}#artists`, - date: chart['date'] - } - }) - return [ - { - title: formattedData['content'], - description: formattedData['description'], - url: `https://coryd.dev/music?ts=${weekNumber}#artists`, - date: now.toISODate() - }, - ...recentChartData - ] - } catch (error) { - console.error('Error:', error.message) - } -} \ No newline at end of file diff --git a/src/feeds/weekly-artist-chart.liquid b/src/feeds/weekly-artist-chart.liquid deleted file mode 100644 index 3d7a631f..00000000 --- a/src/feeds/weekly-artist-chart.liquid +++ /dev/null @@ -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 -%} \ No newline at end of file diff --git a/src/pages/main/feeds.md b/src/pages/main/feeds.md index 675aefe6..0aada3dd 100644 --- a/src/pages/main/feeds.md +++ b/src/pages/main/feeds.md @@ -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. \ No newline at end of file diff --git a/src/pages/main/music/index.html b/src/pages/main/music/index.html index 114bd2ba..f40960f6 100644 --- a/src/pages/main/music/index.html +++ b/src/pages/main/music/index.html @@ -13,7 +13,6 @@ schema: music

This is everything I've been listening to recently — it's collected in a database as I listen to it and displayed here. You can read more about the technical details, if you'd like.

I mostly listen to {{ genres | sortByPlaysDescending: "total_plays" | genreStrings: "name" | mediaLinks: "genre", 5 }}. This week I've listened to {{ music.week.artists.size }} artists, {{ music.week.albums.size }} albums and {{ music.week.totalTracks }} tracks.

{% 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" %}