-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (24 loc) · 924 Bytes
/
index.js
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
27
28
29
30
31
32
import alfy from "alfy";
const HACKERNEWS_API = "https://hacker-news.firebaseio.com/v0/";
const HACKERNEWS_TOP_STORIES = "topstories.json?print=pretty";
const HACKERNEWS_URL = "https://news.ycombinator.com/item?id="
// grab top stories by id and filter for first 10
let topStoryIds = await alfy.fetch(HACKERNEWS_API + HACKERNEWS_TOP_STORIES);
topStoryIds = topStoryIds.slice(0, 10);
const urls = topStoryIds.map((element) => {
const url = HACKERNEWS_API + "item/" + element + ".json";
return url;
});
// grab all the articles and setup json
const articles = await Promise.all(
urls.map(async (element) => {
const response = await alfy.fetch(element, { maxAge: 5000 });
const items = {
title: response.title,
subtitle: [response.by, response.score].join(", "),
arg: 'url' in response? response.url: HACKERNEWS_URL + response.id,
};
return items;
})
);
alfy.output(articles);