import { fetch } from "https://esm.town/v/std/fetch";
export let
const hnTopStories = (async () => {
let valTownFetchLimit = 100;
const topStories: Number[] = await fetch(
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
).then((res) => res.json());
valTownFetchLimit--;
const topStoriesData: Promise<{
title: string;
url: string;
}>[] = topStories.slice(0, valTownFetchLimit).map(async (id) => {
return await fetch(
`https://hacker-news.firebaseio.com/v0/item/${id}.json?print=pretty`
).then((res) => res.json());
});
return `
<ul>
${(await Promise.all(topStoriesData))
.map((story) => {
return `<li><a href="${story.url}">${story.title}</a></li>`;
})
.join("\n")}
</ul>
`;
})();