fix: optionally turn off descending play count sorting; do so for recent tracks

This commit is contained in:
Cory Dransfeldt 2024-05-08 18:36:57 -07:00
parent 5d6da462b8
commit 8248ee018a
No known key found for this signature in database
3 changed files with 7 additions and 6 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "14.0.6", "version": "14.0.7",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -32,7 +32,7 @@ const fetchDataForPeriod = async (startPeriod, fields, table) => {
return rows return rows
} }
const aggregateData = (data, groupByField, groupByType) => { const aggregateData = (data, groupByField, groupByType, sort = true) => {
const aggregation = {} const aggregation = {}
data.forEach(item => { data.forEach(item => {
const key = item[groupByField] const key = item[groupByField]
@ -64,7 +64,8 @@ const aggregateData = (data, groupByField, groupByType) => {
} }
aggregation[key].plays++ aggregation[key].plays++
}) })
return Object.values(aggregation).sort((a, b) => b.plays - a.plays) const aggregatedData = sort ? Object.values(aggregation).sort((a, b) => b.plays - a.plays) : Object.values(aggregation)
return aggregatedData
} }
@ -101,9 +102,9 @@ export default async function() {
results.recent = { results.recent = {
artists: aggregateData(recentData, 'artist_name', 'artists'), artists: aggregateData(recentData, 'artist_name', 'artists'),
albums: aggregateData(recentData, 'album_name', 'albums'), albums: aggregateData(recentData, 'album_name', 'albums'),
tracks: aggregateData(recentData, 'track_name', 'track') tracks: aggregateData(recentData, 'track_name', 'track'),
trackChart: aggregateData(recentData, 'track_name', 'track', false),
} }
results.nowPlaying = results.recent.tracks[0] results.nowPlaying = results.recent.tracks[0]
return results return results

View file

@ -68,7 +68,7 @@ layout: default
</div> </div>
</div> </div>
<div id="tracks-recent"> <div id="tracks-recent">
{% render "partials/now/tracks-recent.liquid", data:music.recent.tracks %} {% render "partials/now/tracks-recent.liquid", data:music.recent.trackChart %}
</div> </div>
<div class="hidden" id="tracks-window"> <div class="hidden" id="tracks-window">
{% render "partials/now/track-chart.liquid", data:music.week.tracks, mostPlayed:music.week.tracks[0].plays %} {% render "partials/now/track-chart.liquid", data:music.week.tracks, mostPlayed:music.week.tracks[0].plays %}