From 606f23a66325dde94404464e8e139add938265b5 Mon Sep 17 00:00:00 2001 From: UltimatChamp Date: Fri, 15 Dec 2023 11:13:40 +0530 Subject: [PATCH] De-Hardcoded the Latest Version Installer Also fixed the indenting! --- assets/js/neoforge.js | 40 +++++++++++++++++++------------- content/_index.md | 3 +-- layouts/shortcodes/files.html | 10 ++++---- layouts/shortcodes/projects.html | 7 ------ 4 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 layouts/shortcodes/projects.html diff --git a/assets/js/neoforge.js b/assets/js/neoforge.js index a29dde0..befd05e 100644 --- a/assets/js/neoforge.js +++ b/assets/js/neoforge.js @@ -3,33 +3,38 @@ const FORGE_GAV = 'net/neoforged/neoforge' const LEGACY_GAV = 'net/neoforged/forge' const LATEST_ENDPOINT = 'https://maven.neoforged.net/api/maven/latest/version/releases/' const DOWNLOAD_URL = 'https://maven.neoforged.net/releases' -//https://maven.neoforged.net/api/maven/latest/version/releases/net%2Fneoforged%2Fneoforge?filter=20.2 +// For the latest version: https://maven.neoforged.net/api/maven/latest/version/releases/net/neoforged/neoforge +// For legacy version(s): https://maven.neoforged.net/api/maven/latest/version/releases/net/neoforged/forge async function loadLatestVersions(minecraftVersions) { for (const mcVersion of minecraftVersions) { let gav; let fn; let mcvers; - let note; - let dropDown_VAL; - let badges_beta; - let badges_new; + let dropDown_VAL; + let badges_beta; + let badges_new; if (mcVersion.startsWith("1.20.1")) { gav = LEGACY_GAV; - fn = "forge"; + fn = "forge"; mcvers = "1.20.1"; - badges_new = ""; - badges_beta = ""; - dropDown_VAL = ""; + badges_new = ""; + badges_beta = ""; + dropDown_VAL = ""; } else { - gav = FORGE_GAV; - fn = "neoforge"; - mcvers = `1.${mcVersion}`; - badges_beta = ""; - badges_new = `NEW`; - dropDown_VAL = ` open="open"`; + gav = FORGE_GAV; + fn = "neoforge"; + badges_beta = ""; + badges_new = `NEW`; + dropDown_VAL = ` open="open"`; } - let currentMcVersionUrl = new URL(LATEST_ENDPOINT + encodeURIComponent(gav) + '?filter=' + encodeURIComponent(mcVersion)); + + let currentMcVersionUrl; let versionJson; + if (mcvers == "1.20.1") { + currentMcVersionUrl = new URL(LATEST_ENDPOINT + encodeURIComponent(gav) + '?filter=' + encodeURIComponent(mcVersion)); + } else { + currentMcVersionUrl = new URL(LATEST_ENDPOINT + encodeURIComponent(gav)); + } try { const response = await fetch(currentMcVersionUrl); @@ -44,6 +49,9 @@ async function loadLatestVersions(minecraftVersions) { if (versionJson) { const {version} = versionJson; + if (mcVersion == "latest") { + mcvers = "1." + Array.from(version)[0] + Array.from(version)[1] + Array.from(version)[2] + Array.from(version)[3]; + } if (version.includes("beta")) { badges_beta = `BETA`; } diff --git a/content/_index.md b/content/_index.md index 3455a1d..314e153 100644 --- a/content/_index.md +++ b/content/_index.md @@ -12,8 +12,7 @@ description: | # NeoForge installer files You can find a direct link to our latest installer files below. - -{{< files "20.4" >}} +{{< files "latest" >}} {{< files "1.20.1" >}} {{< versions >}} diff --git a/layouts/shortcodes/files.html b/layouts/shortcodes/files.html index 37012ed..f9ee53e 100644 --- a/layouts/shortcodes/files.html +++ b/layouts/shortcodes/files.html @@ -16,9 +16,9 @@ diff --git a/layouts/shortcodes/projects.html b/layouts/shortcodes/projects.html deleted file mode 100644 index 3c539e9..0000000 --- a/layouts/shortcodes/projects.html +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file