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();
|
||||
}
|
27
src/data/allActivity.js
Normal file
27
src/data/allActivity.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
export default async function fetchAllActivity() {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_all_activity`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return data?.[0] || [];
|
||||
} catch (error) {
|
||||
console.error("Error fetching activity:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
26
src/data/blogroll.js
Normal file
26
src/data/blogroll.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchBlogroll = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_blogroll`, {
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching and processing the blogroll:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchBlogroll();
|
||||
}
|
57
src/data/books.js
Normal file
57
src/data/books.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllBooks = async () => {
|
||||
try {
|
||||
return await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_books?order=date_finished.desc`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error fetching books:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const sortBooksByYear = (books) => {
|
||||
const years = {};
|
||||
books.forEach((book) => {
|
||||
const year = book.year;
|
||||
if (!years[year]) {
|
||||
years[year] = { value: year, data: [book] };
|
||||
} else {
|
||||
years[year].data.push(book);
|
||||
}
|
||||
});
|
||||
return Object.values(years).filter((year) => year.value);
|
||||
};
|
||||
|
||||
const currentYear = new Date().getFullYear();
|
||||
|
||||
export default async function () {
|
||||
const books = await fetchAllBooks();
|
||||
const sortedByYear = sortBooksByYear(books);
|
||||
const booksForCurrentYear =
|
||||
sortedByYear
|
||||
.find((yearGroup) => yearGroup.value === currentYear)
|
||||
?.data.filter((book) => book.status === "finished") || [];
|
||||
|
||||
return {
|
||||
all: books,
|
||||
years: sortedByYear,
|
||||
currentYear: booksForCurrentYear,
|
||||
feed: books.filter((book) => book.feed),
|
||||
daysRead: books[0]?.days_read
|
||||
};
|
||||
}
|
38
src/data/concerts.js
Normal file
38
src/data/concerts.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllConcerts = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_concerts`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching concerts:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const processConcerts = (concerts) =>
|
||||
concerts.map((concert) => ({
|
||||
...concert,
|
||||
artist: concert.artist || { name: concert.artist_name_string, url: null },
|
||||
}));
|
||||
|
||||
export default async function () {
|
||||
try {
|
||||
const concerts = await fetchAllConcerts();
|
||||
return processConcerts(concerts);
|
||||
} catch (error) {
|
||||
console.error("Error fetching and processing concerts data:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
56
src/data/feeds.js
Normal file
56
src/data/feeds.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchFeeds = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_feeds?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching feed metadata:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const fetchFeedData = async (feedKey) => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/rpc/get_feed_data`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({ feed_key: feedKey }),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error fetching feed data for ${feedKey}:`, error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
const feeds = await fetchFeeds();
|
||||
const feedsWithData = [];
|
||||
|
||||
for (const feed of feeds) {
|
||||
feedsWithData.push({
|
||||
...feed,
|
||||
entries: await fetchFeedData(feed.data),
|
||||
});
|
||||
}
|
||||
|
||||
return feedsWithData;
|
||||
};
|
31
src/data/globals.js
Normal file
31
src/data/globals.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchGlobals = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_globals?select=*`,
|
||||
{
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return data[0];
|
||||
} catch (error) {
|
||||
console.error("Error fetching globals:", error);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchGlobals();
|
||||
}
|
26
src/data/headers.js
Normal file
26
src/data/headers.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchHeaders = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_headers?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching header data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchHeaders();
|
||||
}
|
31
src/data/links.js
Normal file
31
src/data/links.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllLinks = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_links?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching links:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
const links = await fetchAllLinks();
|
||||
|
||||
return {
|
||||
all: links,
|
||||
feed: links.filter((links) => links.feed),
|
||||
}
|
||||
}
|
62
src/data/movies.js
Normal file
62
src/data/movies.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllMovies = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_movies?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching movies:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
try {
|
||||
const movies = await fetchAllMovies();
|
||||
const favoriteMovies = movies.filter((movie) => movie.favorite);
|
||||
const now = new Date();
|
||||
|
||||
const recentlyWatchedMovies = movies.filter((movie) => {
|
||||
const lastWatched = movie.last_watched;
|
||||
if (!lastWatched) return false;
|
||||
|
||||
const lastWatchedDate = new Date(lastWatched);
|
||||
if (isNaN(lastWatchedDate.getTime())) return false;
|
||||
|
||||
const sixMonthsAgo = new Date();
|
||||
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
|
||||
|
||||
return lastWatchedDate >= sixMonthsAgo;
|
||||
});
|
||||
|
||||
return {
|
||||
movies,
|
||||
watchHistory: movies.filter((movie) => movie.last_watched),
|
||||
recentlyWatched: recentlyWatchedMovies,
|
||||
favorites: favoriteMovies.sort((a, b) =>
|
||||
a.title.localeCompare(b.title),
|
||||
),
|
||||
feed: movies.filter((movie) => movie.feed),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching and processing movies data:", error);
|
||||
return {
|
||||
movies: [],
|
||||
watchHistory: [],
|
||||
recentlyWatched: [],
|
||||
favorites: [],
|
||||
feed: [],
|
||||
};
|
||||
}
|
||||
}
|
89
src/data/music.js
Normal file
89
src/data/music.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchDataFromView = async (viewName) => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/${viewName}?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error fetching data from view ${viewName}:`, error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function fetchMusicData() {
|
||||
try {
|
||||
const [
|
||||
recentTracks,
|
||||
weekTracks,
|
||||
weekArtists,
|
||||
weekAlbums,
|
||||
weekGenres,
|
||||
monthTracks,
|
||||
monthArtists,
|
||||
monthAlbums,
|
||||
monthGenres,
|
||||
] = await Promise.all([
|
||||
fetchDataFromView("recent_tracks"),
|
||||
fetchDataFromView("week_tracks"),
|
||||
fetchDataFromView("week_artists"),
|
||||
fetchDataFromView("week_albums"),
|
||||
fetchDataFromView("week_genres"),
|
||||
fetchDataFromView("month_tracks"),
|
||||
fetchDataFromView("month_artists"),
|
||||
fetchDataFromView("month_albums"),
|
||||
fetchDataFromView("month_genres"),
|
||||
]);
|
||||
|
||||
return {
|
||||
recent: recentTracks,
|
||||
week: {
|
||||
tracks: weekTracks,
|
||||
artists: weekArtists,
|
||||
albums: weekAlbums,
|
||||
genres: weekGenres,
|
||||
totalTracks: weekTracks
|
||||
.reduce((acc, track) => acc + track.plays, 0)
|
||||
.toLocaleString("en-US"),
|
||||
},
|
||||
month: {
|
||||
tracks: monthTracks,
|
||||
artists: monthArtists,
|
||||
albums: monthAlbums,
|
||||
genres: monthGenres,
|
||||
totalTracks: monthTracks
|
||||
.reduce((acc, track) => acc + track.plays, 0)
|
||||
.toLocaleString("en-US"),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching and processing music data:", error);
|
||||
return {
|
||||
recent: [],
|
||||
week: {
|
||||
tracks: [],
|
||||
artists: [],
|
||||
albums: [],
|
||||
genres: [],
|
||||
totalTracks: "0",
|
||||
},
|
||||
month: {
|
||||
tracks: [],
|
||||
artists: [],
|
||||
albums: [],
|
||||
genres: [],
|
||||
totalTracks: "0",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
52
src/data/nav.js
Normal file
52
src/data/nav.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllNavigation = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_navigation?select=*`,
|
||||
{
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const nav = data.reduce((acc, item) => {
|
||||
const navItem = {
|
||||
title: item.title || item.page_title,
|
||||
permalink: item.permalink || item.page_permalink,
|
||||
icon: item.icon,
|
||||
sort: item.sort,
|
||||
};
|
||||
|
||||
if (!acc[item.menu_location]) {
|
||||
acc[item.menu_location] = [navItem];
|
||||
} else {
|
||||
acc[item.menu_location].push(navItem);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
Object.keys(nav).forEach((location) => {
|
||||
nav[location].sort((a, b) => a.sort - b.sort);
|
||||
});
|
||||
|
||||
return nav;
|
||||
} catch (error) {
|
||||
console.error("Error fetching navigation data:", error);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchAllNavigation();
|
||||
}
|
42
src/data/nowPlaying.js
Normal file
42
src/data/nowPlaying.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchLatestListen = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_latest_listen?select=*`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const trackData = data[0];
|
||||
if (!trackData) {
|
||||
return { content: "🎧 No recent listens found" };
|
||||
}
|
||||
|
||||
const emoji = trackData.artist_emoji || trackData.genre_emoji || "🎧";
|
||||
|
||||
return {
|
||||
content: `${emoji} ${
|
||||
trackData.track_name
|
||||
} by <a href="https://www.coryd.dev${trackData.url}">${trackData.artist_name}</a>`,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching the latest listen:", error);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchLatestListen();
|
||||
}
|
26
src/data/pages.js
Normal file
26
src/data/pages.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllPages = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_pages?select=*`, {
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching pages:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchAllPages();
|
||||
}
|
34
src/data/posts.js
Normal file
34
src/data/posts.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllPosts = async () => {
|
||||
try {
|
||||
return await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_posts?select=*&order=date.desc`,
|
||||
{
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error fetching posts:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
const posts = await fetchAllPosts();
|
||||
|
||||
return {
|
||||
all: posts,
|
||||
feed: posts.filter((posts) => posts.feed),
|
||||
};
|
||||
}
|
29
src/data/recentActivity.js
Normal file
29
src/data/recentActivity.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
export default async function () {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_recent_activity`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const feeds = data?.[0]?.feed || [];
|
||||
|
||||
return feeds.filter((item) => item !== null);
|
||||
} catch (error) {
|
||||
console.error("Error fetching recent activity:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
33
src/data/recentMedia.js
Normal file
33
src/data/recentMedia.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchRecentMedia = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_recent_media?select=*`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const [{ recent_activity } = {}] = data;
|
||||
|
||||
return recent_activity || [];
|
||||
} catch (error) {
|
||||
console.error("Error fetching recent media data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchRecentMedia();
|
||||
}
|
29
src/data/redirects.js
Normal file
29
src/data/redirects.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchRedirects = async () => {
|
||||
try {
|
||||
return await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_redirects?select=*`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error fetching redirect data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchRedirects();
|
||||
}
|
37
src/data/robots.js
Normal file
37
src/data/robots.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllRobots = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_robots?select=path,user_agents`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const sortedData = data.sort((a, b) => {
|
||||
const aHasWildcard = a.user_agents.includes("*") ? 0 : 1;
|
||||
const bHasWildcard = b.user_agents.includes("*") ? 0 : 1;
|
||||
return aHasWildcard - bHasWildcard || a.path.localeCompare(b.path);
|
||||
});
|
||||
|
||||
return sortedData;
|
||||
} catch (error) {
|
||||
console.error("Error fetching robot data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchAllRobots();
|
||||
}
|
26
src/data/sitemap.js
Normal file
26
src/data/sitemap.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchSitemap = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_sitemap?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching sitemap entries:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchSitemap();
|
||||
}
|
27
src/data/stats.js
Normal file
27
src/data/stats.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_stats?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching stats data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
const stats = await fetchStats();
|
||||
return stats[0];
|
||||
}
|
31
src/data/syndication.js
Normal file
31
src/data/syndication.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchSyndication = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_syndication`,
|
||||
{
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return data?.[0] || [];
|
||||
} catch (error) {
|
||||
console.error("Error fetching syndication data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchSyndication();
|
||||
}
|
31
src/data/topAlbums.js
Normal file
31
src/data/topAlbums.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchTopAlbums = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_albums?select=table&order=total_plays_raw.desc&limit=8`,
|
||||
{
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching top albums:", error);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchTopAlbums();
|
||||
}
|
31
src/data/topArtists.js
Normal file
31
src/data/topArtists.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchTopArtists = async () => {
|
||||
try {
|
||||
const data = await EleventyFetch(
|
||||
`${POSTGREST_URL}/optimized_artists?select=table&order=total_plays_raw.desc&limit=8`,
|
||||
{
|
||||
duration: "1d",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching top artists:", error);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
return await fetchTopArtists();
|
||||
}
|
59
src/data/tv.js
Normal file
59
src/data/tv.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchAllShows = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_shows?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching shows:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
try {
|
||||
const shows = await fetchAllShows();
|
||||
|
||||
const watchedShows = shows.filter(
|
||||
(show) => show.last_watched_at !== null,
|
||||
);
|
||||
|
||||
const episodes = watchedShows.map((show) => ({
|
||||
title: show.episode.title,
|
||||
year: show.year,
|
||||
formatted_episode: show.episode.formatted_episode,
|
||||
url: show.episode.url,
|
||||
image: show.episode.image,
|
||||
backdrop: show.episode.backdrop,
|
||||
last_watched_at: show.episode.last_watched_at,
|
||||
grid: show.grid,
|
||||
}));
|
||||
|
||||
return {
|
||||
shows,
|
||||
recentlyWatched: episodes.slice(0, 125),
|
||||
favorites: shows
|
||||
.filter((show) => show.favorite)
|
||||
.sort((a, b) => a.title.localeCompare(b.title)),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching and processing shows data:", error);
|
||||
|
||||
return {
|
||||
shows: [],
|
||||
recentlyWatched: [],
|
||||
favorites: [],
|
||||
};
|
||||
}
|
||||
}
|
29
src/data/upcomingShows.js
Normal file
29
src/data/upcomingShows.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
const fetchUpcomingShows = async () => {
|
||||
try {
|
||||
return await EleventyFetch(`${POSTGREST_URL}/optimized_scheduled_shows?select=*`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching upcoming shows:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
const data = await fetchUpcomingShows();
|
||||
const upcomingShows = data?.[0]?.scheduled_shows;
|
||||
|
||||
return upcomingShows
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue