feat: initial commit
This commit is contained in:
commit
e214116e40
253 changed files with 17406 additions and 0 deletions
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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue