diff --git a/config/filters/index.js b/config/filters/index.js index 4f3b6a0a..df429c49 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -188,6 +188,7 @@ export default { } return normalized }), + calculatePlayPercentage: (plays, mostPlayed) => `${plays/mostPlayed * 100}%`, // tags filterTags: (tags) => { diff --git a/package.json b/package.json index c55a1b8c..41594a35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "9.5.1", + "version": "9.6.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 71f6d2a6..2a689a9e 100644 --- a/src/_data/helpers/music.js +++ b/src/_data/helpers/music.js @@ -16,9 +16,14 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => { tracks.forEach(track => { if (!tracksData[track['track']]) { tracksData[track['track']] = { + artist: artistCapitalization(track['artist']), title: track['track'], plays: 1, - type: 'track' + type: '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`, } } else { tracksData[track['track']]['plays']++ @@ -56,10 +61,17 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => { } }) + const topTracks = objectToArraySorted(tracksData).splice(0, 10) + const topTracksData = { + data: topTracks, + mostPlayed: Math.max(...topTracks.map(track => track.plays)) + } + return { artists: objectToArraySorted(artistsData), albums: objectToArraySorted(albumsData), tracks: objectToArraySorted(tracksData), + topTracks: topTracksData, nowPlaying } } \ No newline at end of file diff --git a/src/_includes/now.liquid b/src/_includes/now.liquid index 5c8a2023..ce586543 100644 --- a/src/_includes/now.liquid +++ b/src/_includes/now.liquid @@ -53,6 +53,26 @@ layout: default +
+

+ {% tablericon "playlist" "Tracks" %} + Tracks +

+
+ + + +
+
+
+ {% render "partials/now/track-chart.liquid", data:music.topTracks.data, mostPlayed:music.topTracks.mostPlayed %} +
+ + {% render "partials/now/albumReleases.liquid", albumReleases:albumReleases %}

{% tablericon "books" "Books" %} diff --git a/src/_includes/partials/now/track-chart.liquid b/src/_includes/partials/now/track-chart.liquid new file mode 100644 index 00000000..53affc74 --- /dev/null +++ b/src/_includes/partials/now/track-chart.liquid @@ -0,0 +1,24 @@ +{% if data.size > 0 %} + {% capture css %} + {% render "../../../assets/styles/components/track-chart.css" %} + {% render "../../../assets/styles/components/progress-bar.css" %} + {% endcapture %} + +{% endif %} +
+ {% for item in data limit: 10 %} + {%- assign percentage = item.plays | calculatePlayPercentage: mostPlayed -%} +
+
+
{{ forloop.index }}.
+
+
{{ item.title }}
+
+ {{ item.artist }} • {{ item.plays }} plays +
+
+
+ {% render "partials/now/progress-bar.liquid", percentage:percentage %} +
+ {% endfor %} +
\ No newline at end of file diff --git a/src/assets/styles/components/track-chart.css b/src/assets/styles/components/track-chart.css new file mode 100644 index 00000000..7c5b66e2 --- /dev/null +++ b/src/assets/styles/components/track-chart.css @@ -0,0 +1,40 @@ +.track__chart--item { + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.track__chart--item:not(:last-of-type) { + margin-bottom: var(--sizing-md); +} + +.track__chart--item .progress-bar__wrapper { + max-width: 40%; + margin-left: var(--sizing-lg); +} + +.track__chart--presentation { + display: flex; + flex-direction: row; + max-width: calc(60% - var(--sizing-lg)); +} + +.track__chart--count { + margin-right: var(--sizing-sm); +} + +.track__chart--info { + max-width: calc(100% - var(--sizing-lg)); +} + +.track__chart--title { + font-weight: var(--font-weight-bold); + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; +} + +.track__chart--artists { + font-size: var(--font-size-sm); + line-height: var(--line-height-sm); +} \ No newline at end of file