This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/src/data/genres.js

46 lines
No EOL
1.1 KiB
JavaScript

import { createClient } from '@supabase/supabase-js'
import slugify from 'slugify'
import { parseCountryField } from '../../config/utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
const fetchGenresWithArtists = async () => {
const { data, error } = await supabase
.from('genres')
.select(`
name,
description,
total_plays,
wiki_link,
artists (
mbid,
name_string,
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'])
}))
genre['url'] = `/music/genres/${slugify(genre['name'].toLowerCase())}`
})
return data
}
export default async function () {
return await fetchGenresWithArtists()
}