Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,8 @@ Temporary Items
.idea/

/run/

node_modules/
package.json
bun.lock
README-modrinth.md
37 changes: 37 additions & 0 deletions readme-modrinth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 `![${alt}](${new URL(url, BASE_RAW_URL).href})`;
}
return `![${alt}](${url})`;
});

// remove all heading links, modrinth doesn't support them
text = text.replaceAll(/\[(.*?)\]\(#.*\)/g, (_, text) => text);

// save modrinth readme output
modrinthReadme.write(text);

export {};