- {weather.temperature}°{weather.temperatureUnit}
+
+
+ {getWeatherIcon(weather.shortForecast, "w-12 h-12 text-zinc-300")}
+
+
+ {weather.temperature}°
+ {weather.temperatureUnit}
+
+
{weather.shortForecast}
+
-
{weather.shortForecast}
);
}
diff --git a/src/index.ts b/src/index.ts
index d2a0d29..2d09aea 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,6 +3,8 @@ import index from "./index.html";
import { privateApps } from "./data/privateApps";
import { websites } from "./data/websites";
+let hnCache: { stories: any[]; fetchedAt: number } | null = null;
+
async function checkStatuses(items: { name: string; url: string }[]) {
const results = await Promise.all(
items.map(async (item) => {
@@ -39,6 +41,32 @@ const server = serve({
},
},
+ "/api/hackernews": {
+ async GET(req) {
+ if (hnCache && Date.now() - hnCache.fetchedAt < 5 * 60 * 1000) {
+ return Response.json(hnCache.stories);
+ }
+
+ const ids = await fetch(
+ "https://hacker-news.firebaseio.com/v0/topstories.json",
+ ).then((res) => res.json());
+
+ const stories = await Promise.all(
+ ids
+ .slice(0, 5)
+ .map((id: number) =>
+ fetch(
+ `https://hacker-news.firebaseio.com/v0/item/${id}.json`,
+ ).then((res) => res.json()),
+ ),
+ );
+
+ hnCache = { stories, fetchedAt: Date.now() };
+
+ return Response.json(stories);
+ },
+ },
+
"/api/weather": {
async GET(req) {
const url = new URL(req.url);