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
33
import { hnSearch } from "https://esm.town/v/stevekrouse/hnSearch?v=16";
import { hnTagsFromUsernames } from "https://esm.town/v/andreterron/hnTagsFromUsernames?v=2";
export let hnLatestPosts = async ({
authors,
lastSyncTime,
tags,
...params
}: {
authors?: string[];
lastSyncTime?: number | string | Date;
query?: string;
search_by_date?: boolean;
tags?: string;
numericFilters?: string;
page?: number;
restrictSearchableAttributes?: string;
}) => {
let combinedTags = [
authors && (await hnTagsFromUsernames(authors)),
tags,
]
.filter(Boolean)
.join(",");
let results = await hnSearch({
tags: combinedTags,
numericFilters:
lastSyncTime && `created_at_i>${new Date(lastSyncTime).getTime() / 1000}`,
...params,
});
return results?.hits;
};
// Forked from @stevekrouse.hnLatestPosts
đŸ‘† This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.