Runs every 3 days
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// This cron emails Hacker News stories from its API every 3 days.
import { email } from "https://esm.town/v/std/email";
async function fetchStories(type: string, count: number) {
const response = await fetch(`https://hacker-news.firebaseio.com/v0/${type}stories.json`);
const storyIds = await response.json();
const stories = await Promise.all(
storyIds.slice(0, count).map(async (id: number) => {
const storyResponse = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
return storyResponse.json();
}),
);
return stories;
}
function createStoryHTML(story: any) {
return `
<li>
<a href="${
story.url || `https://news.ycombinator.com/item?id=${story.id}`
}" target="_blank" rel="noopener noreferrer">
${story.title}
</a>
<span class="details">(${story.score} points by ${story.by})</span>
</li>
`;
}
function createEmailContent(
topStories: any[],
newStories: any[],
showStories: any[],
askStories: any[],
jobStories: any[],
) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hacker News Digest</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #ff6600;
border-bottom: 2px solid #ff6600;
padding-bottom: 10px;
}
h2 {
color: #3c3c3c;
margin-top: 30px;
}
ul {
padding-left: 20px;
}
li {
margin-bottom: 10px;
}
a {
color: #0066cc;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.details {
font-size: 0.8em;
color: #666;
margin-left: 5px;
}
</style>
</head>
<body>
<h1>Hacker News Digest</h1>
<h2>Top</h2>
<ul>
${topStories.map(createStoryHTML).join("")}
</ul>
<h2>Newest</h2>
<ul>
${newStories.map(createStoryHTML).join("")}
</ul>
<h2>Show HN</h2>
<ul>
${showStories.map(createStoryHTML).join("")}
</ul>
<h2>Ask HN</h2>
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!
September 2, 2024