-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
53 lines (40 loc) · 1.4 KB
/
main.ts
File metadata and controls
53 lines (40 loc) · 1.4 KB
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
import { config } from "https://deno.land/x/dotenv@v3.2.0/mod.ts";
import { Repository } from "./types.ts"
const { GITHUB_USERNAME, GITHUB_TOKEN } = config()
const total: Repository[] = []
let page = 1
try { await Deno.mkdir("out") } catch (_) { /* */ }
while(true) {
console.log(`Getting page: ${page}`)
const res = await fetch(`https://api.github.com/users/${GITHUB_USERNAME}/starred?per_page=100&page=${page}`, {
method: "GET",
headers: {
"Accept": "application/vnd.github+json",
"Authorization": `Bearer ${GITHUB_TOKEN}`
}
});
const stars: Repository[] = await res.json()
if(stars.length == 0) {
break
}
stars.forEach(async (item) => {
console.log(item.full_name)
const topics = item.topics.map((item) => `#${item}`).join(" ")
const contents = [
`# ${item.full_name}`,
``,
item.description,
``,
`URL: ${item.url}`,
``,
`Language: [[${item.language ?? ""}]]`,
``,
`Topics: ${topics}`,
].join("\n")
const filename = `${item.name}.md`
await Deno.writeTextFile(`./out/${filename}`, contents)
})
total.push(...stars)
page++
}
await Deno.writeTextFile('./out/_index.md', total.map((item) => `- [${item.full_name}](./${item.name}) - ${item.description}`).join("\n"))