diff --git a/config/shortcodes/index.js b/config/shortcodes/index.js index 409c579b..e6c52217 100644 --- a/config/shortcodes/index.js +++ b/config/shortcodes/index.js @@ -20,7 +20,7 @@ export const img = async ( sizes = '90vw', formats = ['avif', 'webp', 'jpeg'] ) => { - const widths = [200, 320, 570, 880, 1024, 1248].filter(width => width <= maxWidth); + const widths = [80, 200, 320, 570, 880, 1024, 1248].filter(width => width <= maxWidth); const metadata = await Image(src, { widths: [...widths], formats: [...formats], diff --git a/package.json b/package.json index fe2f7484..31d9eb70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "9.7.1", + "version": "9.8.0", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/src/_data/helpers/music.js b/src/_data/helpers/music.js index 2a689a9e..19039e94 100644 --- a/src/_data/helpers/music.js +++ b/src/_data/helpers/music.js @@ -3,14 +3,14 @@ import artistCapitalizationPatches from '../json/artist-capitalization-patches.j export const artistCapitalization = (artist) => artistCapitalizationPatches[artist?.toLowerCase()] || artist const sanitizeMediaString = (string) => string.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '').replace(/A©|é/g, 'e'); +const artistSanitizedKey = (artist) => `${sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()}` +const albumSanitizedKey = (album) => `${sanitizeMediaString(album).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album.replace(/[:\/\\,'']+/g + , '').replace(/\s+/g, '-').toLowerCase())}` export const buildChart = (tracks, artists, albums, nowPlaying = {}) => { const artistsData = {} const albumsData = {} const tracksData = {} - const artistSanitizedKey = (artist) => `${sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()}` - const albumSanitizedKey = (album) => `${sanitizeMediaString(album).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album.replace(/[:\/\\,'']+/g - , '').replace(/\s+/g, '-').toLowerCase())}` const objectToArraySorted = (inputObject) => Object.values(inputObject).sort((a, b) => b.plays - a.plays) tracks.forEach(track => { @@ -74,4 +74,16 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => { topTracks: topTracksData, nowPlaying } +} + +export const buildTracksWithArt = (tracks, albums) => { + tracks.forEach(track => { + track['image'] = albums[albumSanitizedKey(track['album'])]?.['image'] || `https://cdn.coryd.dev/albums/${sanitizeMediaString(track['artist']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(track['album'].replace(/[:\/\\,'']+/g + , '').replace(/\s+/g, '-').toLowerCase())}.jpg` + track['url'] = (artists[artistSanitizedKey(track['artist'])]?.['mbid'] && artists[artistSanitizedKey(track['artist'])]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistSanitizedKey(track['artist'])]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace( + /\s+/g, + '+' + )}&type=artist` + }) + return tracks } \ No newline at end of file diff --git a/src/_data/musicCharts.js b/src/_data/musicCharts.js index d5dcad0e..b14558b3 100644 --- a/src/_data/musicCharts.js +++ b/src/_data/musicCharts.js @@ -1,12 +1,14 @@ import { readFile } from 'fs/promises' -import { buildChart } from './helpers/music.js' +import { buildChart, buildTracksWithArt } from './helpers/music.js' export default async function () { const monthChart = JSON.parse(await readFile('./src/_data/json/scrobbles-month-chart.json', 'utf8')); const threeMonthChart = JSON.parse(await readFile('./src/_data/json/scrobbles-three-month-chart.json', 'utf8')); const artists = JSON.parse(await readFile('./src/_data/json/artists-map.json', 'utf8')); const albums = JSON.parse(await readFile('./src/_data/json/albums-map.json', 'utf8')); + const recent = JSON.parse(await readFile('./src/_data/json/scrobbles-window.json', 'utf8'))['data'].reverse().splice(0,10) return { + recent: buildTracksWithArt(recent, albums), month: buildChart(monthChart['data'], artists, albums), threeMonthChart: buildChart(threeMonthChart['data'], artists, albums), } diff --git a/src/_includes/now.liquid b/src/_includes/now.liquid index ce586543..21298d97 100644 --- a/src/_includes/now.liquid +++ b/src/_includes/now.liquid @@ -59,12 +59,16 @@ layout: default Tracks
-