diff --git a/src/data/nowPlaying.js b/src/data/nowPlaying.js new file mode 100644 index 00000000..90559f1a --- /dev/null +++ b/src/data/nowPlaying.js @@ -0,0 +1,33 @@ +import { createClient } from '@supabase/supabase-js' + +const SUPABASE_URL = process.env.SUPABASE_URL +const SUPABASE_KEY = process.env.SUPABASE_KEY +const supabase = createClient(SUPABASE_URL, SUPABASE_KEY) + +const fetchNowPlaying = async () => { + const { data, error } = await supabase + .from('optimized_latest_listen') + .select('*') + .single() + + if (error) { + console.error('Error fetching the latest track:', error) + return {} + } + + const genreEmoji = data.genre_emoji + const emoji = data.artist_emoji || genreEmoji + + return { + content: `${emoji || '🎧'} ${data.track_name} by ${data.artist_name}`, + } +} + +export default async function () { + try { + return await fetchNowPlaying() + } catch (error) { + console.error('Error fetching and processing now-playing data:', error) + return {} + } +} \ No newline at end of file diff --git a/src/includes/partials/blocks/now-playing.liquid b/src/includes/partials/blocks/now-playing.liquid index eea3524f..b9d8b08a 100644 --- a/src/includes/partials/blocks/now-playing.liquid +++ b/src/includes/partials/blocks/now-playing.liquid @@ -3,7 +3,6 @@

🎧 Loading...

\ No newline at end of file diff --git a/src/includes/partials/home/intro.liquid b/src/includes/partials/home/intro.liquid index 99ff6e39..acd84847 100644 --- a/src/includes/partials/home/intro.liquid +++ b/src/includes/partials/home/intro.liquid @@ -1,4 +1,4 @@

I'm a software developer based in Camarillo, California. I enjoy hanging out with my beautiful family and 3 rescue dogs, technology, automation, music, writing, reading, tv and movies.

- {% render "partials/blocks/now-playing.liquid", music:music %} + {% render "partials/blocks/now-playing.liquid", nowPlaying:nowPlaying %}
\ No newline at end of file diff --git a/src/pages/dynamic/index.html b/src/pages/dynamic/index.html index 659d51f2..000d437e 100644 --- a/src/pages/dynamic/index.html +++ b/src/pages/dynamic/index.html @@ -2,6 +2,6 @@ layout: default permalink: / --- -{% render "partials/home/intro.liquid" music:music %} +{% render "partials/home/intro.liquid" nowPlaying:nowPlaying.content %} {% render "partials/home/recent-activity.liquid" music:music, books:books.all, tv:tv, movies:movies, links:links %} {% render "partials/home/recent-posts.liquid" posts:posts %} \ No newline at end of file