chore: now playing link
This commit is contained in:
parent
ef5592ab42
commit
d2156c9678
3 changed files with 35 additions and 9 deletions
|
@ -1,8 +1,34 @@
|
|||
import { createClient } from '@supabase/supabase-js';
|
||||
import slugify from 'slugify'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
const sanitizeMediaString = (str) => {
|
||||
const sanitizedString = str.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '')
|
||||
|
||||
return slugify(sanitizedString, {
|
||||
replacement: '-',
|
||||
remove: /[#,&,+()$~%.'":*?<>{}]/g,
|
||||
lower: true,
|
||||
})
|
||||
}
|
||||
|
||||
const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })
|
||||
const getCountryName = (countryCode) => regionNames.of(countryCode.trim()) || countryCode.trim()
|
||||
const parseCountryField = (countryField) => {
|
||||
if (!countryField) return null
|
||||
|
||||
const delimiters = [',', '/', '&', 'and']
|
||||
let countries = [countryField]
|
||||
|
||||
delimiters.forEach(delimiter => {
|
||||
countries = countries.flatMap(country => country.split(delimiter))
|
||||
})
|
||||
|
||||
return countries.map(getCountryName).join(', ')
|
||||
}
|
||||
|
||||
const emojiMap = (genre, artist) => {
|
||||
const DEFAULT = "🎧"
|
||||
|
@ -90,7 +116,7 @@ export default async () => {
|
|||
track_name,
|
||||
artist_name,
|
||||
listened_at,
|
||||
artists (mbid, genre)
|
||||
artists (mbid, genre, country)
|
||||
`)
|
||||
.order('listened_at', { ascending: false })
|
||||
.range(0, 1)
|
||||
|
@ -115,7 +141,7 @@ export default async () => {
|
|||
content: `${emojiMap(
|
||||
scrobbleData.artists.genre,
|
||||
scrobbleData.artist_name
|
||||
)} ${scrobbleData.track_name} by <a href="http://musicbrainz.org/artist/${scrobbleData.artists.mbid}">${
|
||||
)} ${scrobbleData.track_name} by <a href="https://coryd.dev/music/artists/${slugifyString(scrobbleData.artist_name)}-${slugifyString(parseCountryField(scrobbleData.country))}">${
|
||||
scrobbleData.artist_name
|
||||
}</a>`,
|
||||
}), { headers });
|
||||
|
|
Reference in a new issue