forked from VipinVIP/wallpapers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.tsx
executable file
·85 lines (78 loc) · 2.22 KB
/
generate.tsx
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
#!/usr/bin/env -S deno run --allow-read --allow-write
import React from "https://esm.sh/[email protected]";
import { renderToString } from "https://esm.sh/[email protected]/server";
import { parse } from "https://deno.land/[email protected]/encoding/yaml.ts";
interface CategoryInfo {
name: string;
wallpapers: Wallpaper[];
}
interface Wallpaper {
author_name: string;
author_url: string;
source_url: string;
image_url?: string;
}
const Table = (
category: CategoryInfo,
directory: string
): React.ReactElement => {
return (
<>
<h3>{category.name}</h3>
<table>
<thead>
<tr>
<th>Author</th>
</tr>
</thead>
<tbody>
{category.wallpapers.map((info) => {
let imgUrl = info.image_url;
if (!imgUrl.startsWith("http")) {
imgUrl = `https://raw.githubusercontent.com/catppuccin/wallpapers/main/${directory}/${info.image_url}`;
}
return (
<>
<tr>
<td>
<a href={info.author_url}>{info.author_name}</a>
{info.source_url && (
<>
{" "}
<a href={info.source_url}>(Source)</a>
</>
)}
</td>
</tr>
{info.image_url && (
<tr>
<td>
<a href={imgUrl}>
<img src={info.image_url} />
</a>
</td>
</tr>
)}
</>
);
})}
</tbody>
</table>
</>
);
};
for await (const dirEntry of Deno.readDir(".")) {
if (dirEntry.isDirectory) {
let content = "";
try {
content = await Deno.readTextFile(`./${dirEntry.name}/.authors.yml`);
} catch (_) {
console.warn(`No README.md found in ${dirEntry.name}`);
continue;
}
const data = parse(content) as CategoryInfo;
const mdTable = renderToString(Table(data, dirEntry.name));
await Deno.writeTextFile(`${dirEntry.name}/README.md`, mdTable);
console.log(`Generated README.md for ${dirEntry.name}`);
}
}