-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadme-modrinth.ts
More file actions
executable file
·37 lines (29 loc) · 1.14 KB
/
readme-modrinth.ts
File metadata and controls
executable file
·37 lines (29 loc) · 1.14 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
#!/usr/bin/env bun
// readme-modrinth.ts
// Generates a version of README.md that is suitable for use as
// the plugin description on Modrinth.
//
// For this file to work smoothly in your editor, please run:
// bun add --dev @types/bun
// The files generated by this command are included in the gitignore.
const BASE_RAW_URL =
// trailing slash is important!
// otherwise, URL constructor treats `main` as a file, not a directory path
"https://raw.githubusercontent.com/ModernBetaNetwork/AdminToolbox/refs/heads/main/";
const readme = Bun.file("README.md");
const modrinthReadme = Bun.file("README-modrinth.md");
let text = await readme.text();
// remove first h1
text = text.replace(/^(# .+\n+)/, "");
// replace all repo images with GitHub raw url
text = text.replaceAll(/!\[(.*?)\]\((.*?)\)/g, (_, alt, url) => {
if (url.startsWith("./")) {
return `.href})`;
}
return ``;
});
// remove all heading links, modrinth doesn't support them
text = text.replaceAll(/\[(.*?)\]\(#.*\)/g, (_, text) => text);
// save modrinth readme output
modrinthReadme.write(text);
export {};