type ExternalNewsletter = {
title: string;
description: string;
url: string;
};
export default async function ExternalNewsletters() {
try {
const response = await fetch(
"https://us-rse.org/api/newsletters.json", // can go to url to see the response body
{
signal: AbortSignal.timeout(5000), // errors after 5s to stop loading and go to catch
}
);
const numNewsletters = 5; // probably dont want a massively page I also dk how many newsletters the api is gonna return
if (!response.ok) { // display status if not succeeded
throw new Error(`Feed request failed: ${response.status}`);
}
const newsletters: ExternalNewsletter[] = await response.json(); // converts api response body into a list of objects of our type
return (
{newsletter.description}
{/* I am assuming when I pick the first five its the latest 5 */}
Latest from US-RSE
{newsletters.slice(0, numNewsletters).map((newsletter) => ( // slice out varnum from 0 and map them to list items
{newsletter.title}
This source is currently unavailable.
); } }