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-astro/src/components/blocks/NowPlaying.astro

24 lines
No EOL
710 B
Text

---
import { fetchNowPlaying } from "@utils/data/nowPlaying.js";
const isProduction = import.meta.env.MODE === "production";
const nowPlayingData = await fetchNowPlaying();
---
<span class="loading client-side" id="now-playing-content" set:html={nowPlayingData.content}></span>
<noscript>
<p>{nowPlayingData.content}</p>
</noscript>
{isProduction && (<script type="module" is:inline>
async function updateNowPlaying() {
const response = await fetch("/api/now-playing");
if (response.ok) {
const data = await response.json();
document.getElementById("now-playing-content").innerHTML = data.content;
}
}
setInterval(updateNowPlaying, 180000);
updateNowPlaying();
</script>)}