From dceb96909560c44d04a358ea00053483758f18d3 Mon Sep 17 00:00:00 2001 From: Lynx Date: Wed, 24 Dec 2025 05:02:41 -0800 Subject: [PATCH 1/2] add script to generate modrinth-compatible readme --- .gitignore | 5 +++++ readme-modrinth.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 readme-modrinth.ts 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..22002ed --- /dev/null +++ b/readme-modrinth.ts @@ -0,0 +1,38 @@ +#!/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 RELATIVE_PATH_PREFIX = "./"; + +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(RELATIVE_PATH_PREFIX)) { + 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 {}; From b5a0bba557f76a852f84a90c423759de8eb6c2de Mon Sep 17 00:00:00 2001 From: Lynx Date: Wed, 24 Dec 2025 05:04:53 -0800 Subject: [PATCH 2/2] rm variable for relative path prefix --- readme-modrinth.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/readme-modrinth.ts b/readme-modrinth.ts index 22002ed..b3b57d8 100755 --- a/readme-modrinth.ts +++ b/readme-modrinth.ts @@ -12,7 +12,6 @@ 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 RELATIVE_PATH_PREFIX = "./"; const readme = Bun.file("README.md"); const modrinthReadme = Bun.file("README-modrinth.md"); @@ -23,7 +22,7 @@ text = text.replace(/^(# .+\n+)/, ""); // replace all repo images with GitHub raw url text = text.replaceAll(/!\[(.*?)\]\((.*?)\)/g, (_, alt, url) => { - if (url.startsWith(RELATIVE_PATH_PREFIX)) { + if (url.startsWith("./")) { return `![${alt}](${new URL(url, BASE_RAW_URL).href})`; } return `![${alt}](${url})`;