-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
99 lines (89 loc) · 3.28 KB
/
mod.ts
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
import { serve } from "https://deno.land/[email protected]/http/server.ts";
const BASE_URL = "https://factoryfolio.deno.dev";
async function handleRequest(request: Request): Promise<Response> {
const { pathname, searchParams } = new URL(request.url);
if (pathname === "/") {
return new Response(
`<html>
<head>
<title>FactoryFolio</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>FactoryFolio</h1>
<p>Devfolio → FactoryDAO export. The script downloads all projects from a given hackathon and formats them as a CSV ready for import into FactoryDAO.</p>
<p>
CSV file:<i>Project Name, Tagline, Description, Links, Logo, Technology, Project URL, Prize Tracks</i>
</p>
<h2>Usage</h2>
<p>
Just go to url <code>${BASE_URL}/<HackathonSlug></code>
</p>
<h2>Examples</h2>
<ul>
<li>ETHBerlin³: <code>/ethberlin</code> (<a href="/ethberlin">download</a>, <a href="/ethberlin?inline">inline</a>)</li>
<li>ETHBrno²: <code>/ethbrno</code> (<a href="/ethbrno">download</a>, <a href="/ethbrno?inline">inline</a>)</li>
<li>EthereumZuri.ch: <code>/ethereumzurich</code> (<a href="/ethereumzurich">download</a>, <a href="/ethereumzurich?inline">inline</a>)</li>
</ul>
<hr />
<p>
<a href="https://github.com/utxo-foundation/factoryfolio">Source code</a>,
author: <a href="https://twitter.com/treecz">tree</a> (<a href="https://t.me/treecz">telegram</a>)
</p>
</body>
</html>`,
{
headers: {
"content-type": "text/html; charset=utf-8",
},
},
);
}
const hackathonSlug = pathname.replace(/^\//, "");
const req = await fetch("https://api.devfolio.co/api/search/projects", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
hackathon_slugs: [hackathonSlug],
size: 5000,
}),
});
const data = await req.json();
const col = (val) => val ? `"${val.replace(/"/g, '""').replace(/,/g, ',')}"` : '""';
const separator = ",";
const output = [["Project Name", "Logo", "Tagline", "Description", "Links", "Technology", "URL", "Prize Tracks"].map(col).join(separator)];
const list = data.hits.hits || [];
if (searchParams.get("stats") !== null) {
return new Response(JSON.stringify({
projects_count: list.length,
}));
}
for (const hit of list) {
const item = hit._source;
const url = `https://devfolio.co/projects/${item.slug}`;
output.push([
item.name,
item.favicon,
item.tagline,
item.description[0].content,
item.links,
item.hashtags.map((m) => m.name).join(","),
url,
item.prize_tracks?.map((m) => m.name).join(","),
].map(col).join(separator));
}
return new Response(output.join("\n"), {
headers: {
"Content-Disposition": (
searchParams.get("inline") !== null
? "inline"
: `attachment; filename="${hackathonSlug}_projects_${
(new Date()).toISOString().replace(/:\./, "_")
}.csv"`
),
},
});
}
serve(handleRequest);