diff --git a/src/_data/lastfm.js b/src/_data/lastfm.js index 7961bf3..39dc6a5 100644 --- a/src/_data/lastfm.js +++ b/src/_data/lastfm.js @@ -10,6 +10,35 @@ dayjs.extend(relativeTime); const lastFmApiKey = process.env.LAST_FM_API_KEY; +const baseUrl = "http://ws.audioscrobbler.com"; +const username = "wonderfulfrog"; + +const fetchRecentAlbums = async (period = "7day") => { + const path = `/2.0/?method=user.gettopalbums&user=${username}&api_key=${lastFmApiKey}&format=json`; + const url = `${baseUrl}${path}&period=${period}`; + + const response = await EleventyFetch(url, { duration: "7d", type: "json" }); + const albums = response.topalbums.album.slice(0, 8); + + const recentAlbums = albums.map((album) => { + const extraLargeImage = album.image.find( + (img) => img.size === "extralarge", + ); + const imageUrl = extraLargeImage ? extraLargeImage["#text"] : ""; + return { + artist: album.artist.name, + artistMbid: album.artist.mbid, + album: album.name, + albumMbid: album.mbid, + playcount: album.playcount, + url: album.url, + imageUrl, + }; + }); + + return recentAlbums; +}; + const fetchRecentTracks = async () => { const url = `http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=wonderfulfrog&api_key=${lastFmApiKey}&format=json`; @@ -31,4 +60,12 @@ const fetchRecentTracks = async () => { return recentTracks; }; -module.exports = fetchRecentTracks; +module.exports = async function () { + const recentTracks = await fetchRecentTracks(); + const recentAlbums = await fetchRecentAlbums(); + + return { + recentTracks, + recentAlbums, + }; +}; diff --git a/src/css/blocks/now.css b/src/css/blocks/now.css index 1e16204..27cf39a 100644 --- a/src/css/blocks/now.css +++ b/src/css/blocks/now.css @@ -9,8 +9,10 @@ grid-gap: var(--spacing-0\.5); } -@supports (width: min(100px, 100%)) { - .media-grid { - grid-template-columns: repeat(auto-fit, minmax(min(100px, 100%), 1fr)); - } +.media-grid.square { + grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); +} + +.media-grid.poster { + grid-template-columns: repeat(auto-fit, minmax(min(100px, 100%), 1fr)); } diff --git a/src/now.html b/src/now.html index d2300b3..7e3142d 100644 --- a/src/now.html +++ b/src/now.html @@ -4,32 +4,40 @@ permalink: /now/index.html title: /now --- +{% set recentTrack = lastfm.recentTracks[0] %}
What am I doing right now? Everything on here is automatically generated from various data sources.
- What is a `/now` page? Check out nownownow.com. + 🎶 {{ recentTrack.artist }} - {{ recentTrack.track }}
-{{ track.timestamp }}
+ rel="external noreferrer noopener"> +{{ album.artist }} - {{ album.album }}
+ {% image album.imageUrl, "" %} +{{ movie.title }}
- {% image movie.imgSrc, "", "", "[ movie-poster ]" %} + {% image movie.imgSrc, "" %}+ What is a `/now` page? Check out nownownow.com. +