diff --git a/.gitignore b/.gitignore index 719541a..f0f2092 100644 --- a/.gitignore +++ b/.gitignore @@ -287,3 +287,8 @@ Temporary Items .idea/ /run/ + +node_modules/ +package.json +bun.lock +README-modrinth.md diff --git a/readme-modrinth.ts b/readme-modrinth.ts new file mode 100755 index 0000000..b3b57d8 --- /dev/null +++ b/readme-modrinth.ts @@ -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 {};