Skip to content

Commit

Permalink
De-Hardcoded the Latest Version Installer
Browse files Browse the repository at this point in the history
Also fixed the indenting!
  • Loading branch information
UltimatChamp committed Dec 15, 2023
1 parent 46bcee7 commit 606f23a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
40 changes: 24 additions & 16 deletions assets/js/neoforge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<font class="badges_new">NEW</font>`;
dropDown_VAL = ` open="open"`;
gav = FORGE_GAV;
fn = "neoforge";
badges_beta = "";
badges_new = `<font class="badges_new">NEW</font>`;
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);
Expand All @@ -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 = `<font class="badges_beta">BETA</font>`;
}
Expand Down
3 changes: 1 addition & 2 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ description: |
# NeoForge installer files
You can find a direct link to our latest installer files below.

<!--Change with the latest version here-->
{{< files "20.4" >}}
{{< files "latest" >}}
{{< files "1.20.1" >}}
{{< versions >}}

Expand Down
10 changes: 5 additions & 5 deletions layouts/shortcodes/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
</div>

<script>
document.addEventListener("readystatechange", evt=>{
if (evt.target.readyState === "complete") {
loadLatestVersions([{{ .Get 0 }}]);
}
});
document.addEventListener("readystatechange", evt=>{
if (evt.target.readyState === "complete") {
loadLatestVersions([{{ .Get 0 }}]);
}
});
</script>
7 changes: 0 additions & 7 deletions layouts/shortcodes/projects.html

This file was deleted.

1 comment on commit 606f23a

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying with Cloudflare Pages

Name Result
Last commit: 606f23a66325dde94404464e8e139add938265b5
Status: ✅ Deploy successful!
Preview URL: https://0743dd4c.neoforged-website-previews.pages.dev
PR Preview URL: https://pr-15.neoforged-website-previews.pages.dev

Please sign in to comment.