chore: statically populate now playing

This commit is contained in:
Cory Dransfeldt 2024-10-09 18:40:26 -07:00
parent 1880790c05
commit 212745f52d
No known key found for this signature in database
4 changed files with 36 additions and 4 deletions

33
src/data/nowPlaying.js Normal file
View file

@ -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 <a href="https://coryd.dev${data.url}">${data.artist_name}</a>`,
}
}
export default async function () {
try {
return await fetchNowPlaying()
} catch (error) {
console.error('Error fetching and processing now-playing data:', error)
return {}
}
}

View file

@ -3,7 +3,6 @@
<p class="loading client-side">🎧 Loading...</p>
<p class="content"></p>
<noscript>
{%- assign track = music.recent | first -%}
<p>🎧 {{ track.title }} by <a href="{{ track.url }}">{{ track.artist }}</a></p>
<p>{{ nowPlaying }}</p>
</noscript>
</api-text>

View file

@ -1,4 +1,4 @@
<article>
<p><strong class="highlight-text">I'm a software developer based in Camarillo, California</strong>. I enjoy hanging out with my beautiful family and 3 rescue dogs, technology, automation, <a href="/music">music</a>, <a href="/posts">writing</a>, <a href="/books">reading</a>, <a href="/watching#tv">tv</a> and <a href="/watching#movies">movies</a>.</p>
{% render "partials/blocks/now-playing.liquid", music:music %}
{% render "partials/blocks/now-playing.liquid", nowPlaying:nowPlaying %}
</article>

View file

@ -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 %}