1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { fetch } from "https://esm.town/v/std/fetch";
// forked from @healeycodes.hnTopStories
// just returns the top HN story in glif-friendly format (single value in the 'data' param)
// hi florian
export const hnTopStories = async () => {
let valTownFetchLimit = 1;
const topStories: Number[] = await fetch(
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
).then((res) => res.json());
valTownFetchLimit--;
const id = topStories[0];
console.log({ id });
const story: {
title: string;
url: string;
time: number;
type: string;
score: number;
by: string;
} = await fetch(
`https://hacker-news.firebaseio.com/v0/item/${id}.json?print=pretty`
).then((res) => res.json());
return `${new Date()} - ${story.title}`;
};
// Forked from @jamiedubs.hnTopStories
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023