feat: initial commit

This commit is contained in:
Cory Dransfeldt 2025-03-27 16:46:02 -07:00
commit e214116e40
No known key found for this signature in database
253 changed files with 17406 additions and 0 deletions

60
src/data/albumReleases.js Normal file
View file

@ -0,0 +1,60 @@
import EleventyFetch from "@11ty/eleventy-fetch";
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
const fetchAlbumReleases = async () => {
try {
const data = await EleventyFetch(
`${POSTGREST_URL}/optimized_album_releases`,
{
duration: "1d",
type: "json",
fetchOptions: {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${POSTGREST_API_KEY}`,
},
},
},
);
const pacificNow = new Date().toLocaleString("en-US", {
timeZone: "America/Los_Angeles",
});
const pacificDate = new Date(pacificNow);
pacificDate.setHours(0, 0, 0, 0);
const todayTimestamp = pacificDate.getTime() / 1000;
const all = data
.map((album) => {
const releaseDate = new Date(album.release_timestamp * 1000);
return {
...album,
description: album.artist?.description || "No description",
date: releaseDate.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
}),
};
})
.sort((a, b) => a.release_timestamp - b.release_timestamp);
const upcoming = all.filter(
(album) =>
album.release_timestamp > todayTimestamp &&
album.total_plays === 0,
);
return { all, upcoming };
} catch (error) {
console.error("Error fetching and processing album releases:", error);
return { all: [], upcoming: [] };
}
};
export default async function () {
return await fetchAlbumReleases();
}