chore: now playing link

This commit is contained in:
Cory Dransfeldt 2024-05-23 19:11:52 -07:00
parent ef5592ab42
commit d2156c9678
No known key found for this signature in database
3 changed files with 35 additions and 9 deletions

View file

@ -1,8 +1,34 @@
import { createClient } from '@supabase/supabase-js'; import { createClient } from '@supabase/supabase-js';
import slugify from 'slugify'
const SUPABASE_URL = process.env.SUPABASE_URL const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY 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 emojiMap = (genre, artist) => {
const DEFAULT = "🎧" const DEFAULT = "🎧"
@ -90,7 +116,7 @@ export default async () => {
track_name, track_name,
artist_name, artist_name,
listened_at, listened_at,
artists (mbid, genre) artists (mbid, genre, country)
`) `)
.order('listened_at', { ascending: false }) .order('listened_at', { ascending: false })
.range(0, 1) .range(0, 1)
@ -115,7 +141,7 @@ export default async () => {
content: `${emojiMap( content: `${emojiMap(
scrobbleData.artists.genre, scrobbleData.artists.genre,
scrobbleData.artist_name 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 scrobbleData.artist_name
}</a>`, }</a>`,
}), { headers }); }), { headers });

10
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "17.0.3", "version": "17.0.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "17.0.3", "version": "17.0.4",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.2.2", "@cdransf/api-text": "^1.2.2",
@ -3346,9 +3346,9 @@
"dev": true "dev": true
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.4.781", "version": "1.4.782",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.781.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.782.tgz",
"integrity": "sha512-aBI40ltvcWJQDW+V803FY6HjXAfi5xCWzpa3vSM/NGg7GfKEvI7ftzW4Gb2XKTRO4WsxDG7YG8ykrr/pG9bkKQ==", "integrity": "sha512-JUfU61e8tr+i5Y1FKXcKs+Xe+rJ+CEqm4cgv1kMihPE2EvYHmYyVr3Im/+1+Z5B29Be2EEGCZCwAc6Tazdl1Yg==",
"dev": true "dev": true
}, },
"node_modules/encodeurl": { "node_modules/encodeurl": {

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "17.0.3", "version": "17.0.4",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {