feat: initial commit
This commit is contained in:
commit
e214116e40
253 changed files with 17406 additions and 0 deletions
60
src/data/albumReleases.js
Normal file
60
src/data/albumReleases.js
Normal 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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue