diff --git a/package.json b/package.json index f2bc985b..c9b6680a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "9.8.2", + "version": "9.8.3", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/plugins/fetch-scrobbles/index.js b/plugins/fetch-scrobbles/index.js index 579370ce..862328f0 100644 --- a/plugins/fetch-scrobbles/index.js +++ b/plugins/fetch-scrobbles/index.js @@ -18,6 +18,16 @@ const getKeys = (months = 1) => { return keys } +const filterOldScrobbles = (scrobbles, months = 1) => { + const currentDate = DateTime.now() + const weeks = Math.floor((currentDate.daysInMonth * months) / 7) + const windowEnd = DateTime.now().minus({ weeks }); + return scrobbles.filter(scrobble => { + const timestamp = DateTime.fromISO(scrobble.timestamp); + return timestamp >= windowEnd; + }); +} + export const onPreBuild = async ({ constants }) => { setEnvironmentContext({ siteID: constants.SITE_ID, @@ -50,6 +60,6 @@ export const onPreBuild = async ({ constants }) => { fs.writeFileSync('./src/_data/json/artists-map.json', JSON.stringify(artistsMap)) fs.writeFileSync('./src/_data/json/albums-map.json', JSON.stringify(albumsMap)) fs.writeFileSync('./src/_data/json/now-playing.json', JSON.stringify(nowPlaying)) - fs.writeFileSync('./src/_data/json/scrobbles-month-chart.json', JSON.stringify(monthChartData)) - fs.writeFileSync('./src/_data/json/scrobbles-three-month-chart.json', JSON.stringify(threeMonthChartData)) + fs.writeFileSync('./src/_data/json/scrobbles-month-chart.json', JSON.stringify({ data: filterOldScrobbles(monthChartData.data) })) + fs.writeFileSync('./src/_data/json/scrobbles-three-month-chart.json', JSON.stringify({ data: filterOldScrobbles(threeMonthChartData.data, 3) })) } \ No newline at end of file