forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme-styles.ts
More file actions
89 lines (83 loc) 路 2.36 KB
/
Copy pathreadme-styles.ts
File metadata and controls
89 lines (83 loc) 路 2.36 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
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
import type { UserstylesSchema } from "@/types/mod.ts";
import { REPO_ROOT } from "@/constants.ts";
import * as path from "@std/path";
import Handlebars from "handlebars";
import { formatListOfItems } from "@/utils.ts";
// we can have some nice things :)
Handlebars.registerHelper(
"pluralize",
(c: number | unknown[], str: string): string => {
if (typeof c === "undefined") return str;
const num = Array.isArray(c) ? c.length : c;
return num === 1 ? str : `${str}s`;
},
);
const heading = (
name: UserstylesSchema.Name,
link: UserstylesSchema.Link,
supports: UserstylesSchema.Supports | undefined,
) => {
return [{ title: name, url: link }].concat(
Object.values(supports ?? {}).map(({ name, link }) => ({
title: name,
url: link,
})),
);
};
function getNameWithGitHubUrl(
collaborators?:
| UserstylesSchema.CurrentMaintainers
| UserstylesSchema.PastMaintainers,
) {
// no-op when undefined
if (!collaborators) return;
// keep name & set the url to the github.com/<name>
return collaborators.map((name) => {
return {
name,
url: `https://github.com/${name}`,
};
});
}
export function generateStyleReadmes(userstyles: UserstylesSchema.Userstyles) {
const stylesReadmePath = path.join(
REPO_ROOT,
"scripts/generate/templates/userstyle.md",
);
const stylesReadmeContent = Deno.readTextFileSync(stylesReadmePath);
Object.entries(userstyles).map(
(
[
slug,
{
name,
link,
note,
supports,
"current-maintainers": currentMaintainers,
"past-maintainers": pastMaintainers,
},
],
) => {
console.log(`Generating README for styles/${slug}...`);
const readmeContent = Handlebars.compile(stylesReadmeContent)({
heading: heading(name, link, supports),
supportedWebsites: formatListOfItems(
Object.values(supports ?? {}).map(({ name, link }) =>
`[${name}](${link})`
),
),
slug,
note,
collaborators: {
currentMaintainers: getNameWithGitHubUrl(currentMaintainers),
pastMaintainers: getNameWithGitHubUrl(pastMaintainers),
},
});
Deno.writeTextFile(
path.join(REPO_ROOT, "styles", slug.toString(), "README.md"),
readmeContent,
).catch((e) => console.error(e));
},
);
}