feat: genre pages

This commit is contained in:
Cory Dransfeldt 2024-05-26 14:25:03 -07:00
parent f6ec72f469
commit 086a7bf6c9
No known key found for this signature in database
29 changed files with 165 additions and 67 deletions

41
src/_data/genres.js Normal file
View file

@ -0,0 +1,41 @@
import { createClient } from '@supabase/supabase-js'
import { parseCountryField } from './utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL || 'YOUR_SUPABASE_URL'
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'YOUR_SUPABASE_KEY'
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
export default async function fetchGenresWithArtists() {
const { data, error } = await supabase
.from('genres')
.select(`
name,
description,
total_plays,
wiki_link,
artists (
mbid,
name_string,
image,
total_plays,
country,
description,
favorite
)
`)
.order('id', { ascending: true })
if (error) {
console.error('Error fetching genres with artists:', error)
return []
}
data.forEach(genre => {
genre.artists = genre.artists.map(artist => ({
...artist,
country: parseCountryField(artist.country)
}))
})
return data
}

View file

@ -111,9 +111,9 @@ const aggregateGenres = (data) => {
if (!genreAggregation[genre]) {
genreAggregation[genre] = { genre, plays: 0 }
}
genreAggregation[genre].plays++
genreAggregation[genre]['plays']++
})
return Object.values(genreAggregation).sort((a, b) => b.plays - a.plays)
return Object.values(genreAggregation).sort((a, b) => b['plays'] - a['plays'])
}
export default async function() {

View file

@ -1,6 +1,7 @@
import slugify from 'slugify'
export const sanitizeMediaString = (str) => {
if (!str) return null
const sanitizedString = str.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '')
return slugify(sanitizedString, {

View file

@ -1,30 +1,28 @@
{% if data.size > 0 %}
{% assign media = data | normalizeMedia %}
<div class="media-grid {% if shape == 'square' %}square{% else %}vertical{% endif %}">
{% for item in media limit: count %}
{% assign alt = item.alt | strip | escape %}
<a href="{{ item.url | stripUtm }}" title="{{ alt }}">
<div class="item-wrapper shadow">
<div class="meta-text">
{% if item.title %}
<div class="header">{{ item.title }}</div>
{% endif %}
{% if item.subtext %}
<div class="subheader">
{{ item.subtext }}
</div>
{% endif %}
</div>
{%- capture loadingStrategy -%}
{%- if loading -%}{{ loading }}{%- else -%}lazy{%- endif -%}
{%- endcapture -%}
{% if shape == 'square' %}
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=240&h=240&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="{{ loadingStrategy }}" decoding="async" width="240" height="240" />
{% else %}
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=200&h=307&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="{{ loadingStrategy }}" decoding="async" width="200" height="307" />
{% assign media = data | normalizeMedia %}
<div class="media-grid {% if shape == 'square' %}square{% else %}vertical{% endif %}">
{% for item in media limit: count %}
{% assign alt = item.alt | strip | escape %}
<a href="{{ item.url | stripUtm }}" title="{{ alt }}">
<div class="item-wrapper shadow">
<div class="meta-text">
{% if item.title %}
<div class="header">{{ item.title }}</div>
{% endif %}
{% if item.subtext %}
<div class="subheader">
{{ item.subtext }}
</div>
{% endif %}
</div>
</a>
{% endfor %}
</div>
{% endif %}
{%- capture loadingStrategy -%}
{%- if loading -%}{{ loading }}{%- else -%}lazy{%- endif -%}
{%- endcapture -%}
{% if shape == 'square' %}
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=240&h=240&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="{{ loadingStrategy }}" decoding="async" width="240" height="240" />
{% else %}
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=200&h=307&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="{{ loadingStrategy }}" decoding="async" width="200" height="307" />
{% endif %}
</div>
</a>
{% endfor %}
</div>

View file

@ -1,6 +1,6 @@
{% assign filteredTags = tags | filterTags %}
<div{% if hasSpace %} style="margin-bottom:var(--sizing-md)"{% endif %}>
{% for tag in filteredTags limit: 10 %}
<a class="post-tag" href="/tags/{{ tag | downcase }}">{{ tag | formatTag }}</a>
<a class="tag-element" href="/tags/{{ tag | downcase }}">{{ tag | formatTag }}</a>
{% endfor %}
</div>

View file

@ -477,7 +477,7 @@ article {
}
}
.post-tag {
.tag-element {
margin-bottom: var(--sizing-lg);
display: inline-block;
@ -639,7 +639,7 @@ li {
}
}
.post-tag {
.tag-element {
margin-bottom: var(--sizing-sm);
&:not(:last-child) {

View file

@ -1,6 +1,4 @@
.artist-focus {
border-bottom: 0;
& img {
border: 1px solid var(--accent-color);
}
@ -51,6 +49,11 @@
}
}
.artist-focus,
.genre-focus {
border-bottom: 0;
}
@media screen and (min-width: 768px) {
.artist-focus {
& .artist-display {

View file

@ -4,7 +4,7 @@ pagination:
data: books
size: 1
alias: book
permalink: /books/{{ book.isbn }}/
permalink: /books/{{ book.isbn }}/index.html
isbn: {{ book.isbn }}
schema: book
---

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.threeMonth.albums.size }} albums</strong> over the last 3 months and most of what I've listened to has been <strong class="highlight-text">{{ music.threeMonth.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.threeMonth.albums.size }} albums</strong> over the last 3 months and most of what I've listened to has been {{ music.threeMonth.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/three-months/">artists</a> or <a href="/music/tracks/three-months/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.allTime.albums.size }} albums</strong> and most of what I listen to is <strong class="highlight-text">{{ music.allTime.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.allTime.albums.size }} albums</strong> and most of what I listen to is {{ music.allTime.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/all-time/">artists</a> or <a href="/music/tracks/all-time/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.month.albums.size }} albums</strong> this month and most of what I've listened to has been <strong class="highlight-text">{{ music.month.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.month.albums.size }} albums</strong> this month and most of what I've listened to has been {{ music.month.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/this-month/">artists</a> or <a href="/music/tracks/this-month/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.week.albums.size }} albums</strong> this week and most of what I've listened to has been <strong class="highlight-text">{{ music.week.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.week.albums.size }} albums</strong> this week and most of what I've listened to has been {{ music.week.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/this-week/">artists</a> or <a href="/music/tracks/this-week/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.threeMonth.artists.size }} artists</strong> over the last 3 months and most of what I've listened to has been <strong class="highlight-text">{{ music.threeMonth.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.threeMonth.artists.size }} artists</strong> over the last 3 months and most of what I've listened to has been {{ music.threeMonth.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/albums/three-months/">albums</a> or <a href="/music/tracks/three-months/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.allTime.artists.size }} artists</strong> and most of what I listen to is <strong class="highlight-text">{{ music.allTime.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.allTime.artists.size }} artists</strong> and most of what I listen to is {{ music.allTime.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/albums/all-time/">albums</a> or <a href="/music/tracks/all-time/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -4,7 +4,7 @@ pagination:
data: artists
size: 1
alias: artist
permalink: /music/artists/{{ artist.name_string | slugify | downcase }}-{{ artist.country | slugify | downcase}}/
permalink: /music/artists/{{ artist.name_string | slugify | downcase }}-{{ artist.country | slugify | downcase}}/index.html
updated: "now"
schema: artist
---
@ -28,14 +28,18 @@ schema: artist
{%- if artist.total_plays > 0 -%}
<p class="sub-meta"><strong class="highlight-text">{{ artist.total_plays }} plays</strong></p>
{%- endif -%}
<p class="sub-meta">{{ artist.genre }}</p>
<p class="sub-meta">
<a href="https://coryd.dev/music/genre/{{ artist.genre | slugify | downcase }}">
{{ artist.genre }}
</a>
</p>
<p class="sub-meta">
<a class="brain" href="https://musicbrainz.org/artist/{{ artist.mbid }}">{% tablericon "brain" "MusicBrainz" %}</a>
</p>
</div>
</div>
{%- if artist.description -%}
<div data-toggle-content class="text-toggle-hidden">{{ artist.description | markdown }}</div>
<div data-toggle-content class="text-toggle-hidden"><em>{{ artist.description | markdown }}</em></div>
<button data-toggle-button>Show more</button>
{%- endif -%}
<table>

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.month.artists.size }} artists</strong> this month and most of what I've listened to has been <strong class="highlight-text">{{ music.month.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.month.artists.size }} artists</strong> this month and most of what I've listened to has been {{ music.month.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/albums/this-month/">albums</a> or <a href="/music/tracks/this-month/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.week.artists.size }} artists</strong> this week and most of what I've listened to has been <strong class="highlight-text">{{ music.week.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.week.artists.size }} artists</strong> this week and most of what I've listened to has been {{ music.week.genres | sortByPlaysDescending | genreStrings: "genre" | genreLinks: 5 }}.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/albums/this-week/">albums</a> or <a href="/music/tracks/this-week/">tracks</a> for this period.</p>
{% render "partials/media/music/period/grid.liquid" data:pagination %}

View file

@ -0,0 +1,30 @@
---
layout: default
pagination:
data: genres
size: 1
alias: genre
permalink: /music/genre/{{ genre.name | slugify | downcase }}/index.html
updated: "now"
schema: genre
---
{% assign artists = pagination.artists %}
{% capture js %}
{% render "../../../assets/scripts/text-toggle.js" %}
{% endcapture %}
<script>{{ js }}</script>
<noscript><style>[data-toggle-content].text-toggle-hidden {height: unset !important;overflow: unset !important;margin-bottom: unset !important;}[data-toggle-content].text-toggle-hidden::after {display: none !important;}</style></noscript>
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ genre.name }}</h2>
<article class="genre-focus">
<p>My top <strong class="highlight-text">{{ genre.name }}</strong> artists are <strong class="highlight-text">{{ genre.artists | sortByPlaysDescending | listToString: "name_string", 5 }}</strong>. I've listened to <strong class="highlight-text">{{ genre.name }}</strong> tracks <strong class="highlight-text">{{ genre.total_plays | formatNumber }}</strong> times.</p>
<hr class="large-spacing" />
{%- if genre.description -%}
<div data-toggle-content class="text-toggle-hidden">
<em>{{ genre.description | markdown }}</em>
<p><a href="{{ genre.wiki_link }}">Continue reading at Wikipedia.</a></p>
<p class="text-small"><em>Wikipedia content provided under the terms of the <a href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons BY-SA license</a></em></p>
</div>
<button data-toggle-button>Show more</button>
{%- endif -%}
</article>

View file

@ -11,7 +11,7 @@ schema: music
<script>{{ js }}</script>
<h2 class="page-header">{{ title }}</h2>
<p>This is everything I've been listening to recently — it's collected in a database as I listen to it and displayed here. <a href="https://coryd.dev/posts/2024/improving-my-self-hosted-scrobbling-implementation/">You can read more about the technical details, if you'd like.</a></p>
<p>I mostly listen to <strong class="highlight-text">{{ music.allTime.genres | genresToString: 5 }}</strong>. This week I've listened to <strong class="highlight-text">{{ music.week.artists.size }} artists</strong>, <strong class="highlight-text">{{ music.week.albums.size }} albums</strong> and <strong class="highlight-text">{{ music.week.totalTracks }} tracks</strong>.</p>
<p>I mostly listen to {{ genres | sortByPlaysDescending | genreStrings: "name" | genreLinks: 5 }}. This week I've listened to <strong class="highlight-text">{{ music.week.artists.size }} artists</strong>, <strong class="highlight-text">{{ music.week.albums.size }} albums</strong> and <strong class="highlight-text">{{ music.week.totalTracks }} tracks</strong>.</p>
{% render "partials/widgets/now-playing.liquid" %}
{% render "partials/banners/rss.liquid", url: "https://feedpress.me/coryd-artist-charts", text: "I also have a feed of weekly artist charts I generate from this data" %}
<hr class="large-spacing" />

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.threeMonth.totalTracks }} tracks</strong> over the last 3 months and most of what I've listened to has been <strong class="highlight-text">{{ music.threeMonth.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.threeMonth.totalTracks }} tracks</strong> over the last 3 months and most of what I've listened to has been <strong class="highlight-text">{{ music.threeMonth.genres | listToString: "genre", 5 }}</strong>.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/three-months/">artists</a> or <a href="/music/albums/three-months/">albums</a> for this period.</p>
{% render "partials/media/music/period/chart.liquid" data:pagination, playTotal: music.threeMonth.tracks[0].plays %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.allTime.totalTracks }} tracks</strong> and most of what I've listened to has been <strong class="highlight-text">{{ music.allTime.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.allTime.totalTracks }} tracks</strong> and most of what I've listened to has been <strong class="highlight-text">{{ music.allTime.genres | listToString: "genre", 5 }}</strong>.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/all-time/">artists</a> or <a href="/music/albums/all-time/">albums</a> for this period.</p>
{% render "partials/media/music/period/chart.liquid" data:pagination, playTotal: music.allTime.tracks[0].plays %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.month.totalTracks }} tracks</strong> this month and most of what I've listened to has been <strong class="highlight-text">{{ music.month.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.month.totalTracks }} tracks</strong> this month and most of what I've listened to has been <strong class="highlight-text">{{ music.month.genres | listToString: "genre", 5 }}</strong>.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/this-month/">artists</a> or <a href="/music/albums/this-month/">albums</a> for this period.</p>
{% render "partials/media/music/period/chart.liquid" data:pagination, playTotal: music.month.tracks[0].plays %}

View file

@ -10,6 +10,6 @@ schema: music
---
<a class="back-link-header link-icon flex-centered" href="/music">{% tablericon "arrow-left" "Go back" %} Go back</a>
<h2 class="page-header">{{ title }}</h2>
<p>I've listened to <strong class="highlight-text">{{ music.week.totalTracks }} tracks</strong> this week and most of what I've listened to has been <strong class="highlight-text">{{ music.week.genres | genresToString: 5 }}</strong>.</p>
<p>I've listened to <strong class="highlight-text">{{ music.week.totalTracks }} tracks</strong> this week and most of what I've listened to has been <strong class="highlight-text">{{ music.week.genres | listToString: "genre", 5 }}</strong>.</p>
<p><strong class="highlight-text">See my</strong> <a href="/music/artists/this-week/">artists</a> or <a href="/music/albums/this-week/">albums</a> for this period.</p>
{% render "partials/media/music/period/chart.liquid" data:pagination, playTotal: music.week.tracks[0].plays %}

View file

@ -4,7 +4,7 @@ pagination:
data: movies.movies
size: 1
alias: movie
permalink: /watching/movies/{{ movie.id }}/
permalink: /watching/movies/{{ movie.id }}/index.html
schema: movie
---
{%- capture alt -%}

View file

@ -4,7 +4,7 @@ pagination:
data: tv.shows
size: 1
alias: show
permalink: /watching/shows/{{ show.tmdb_id }}/
permalink: /watching/shows/{{ show.tmdb_id }}/index.html
schema: show
---
{%- capture alt -%}