Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a built-in changelog page (updated) #49

Merged
merged 11 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ hugo.exe
*.sublime-project
*.sublime-workspace
.vscode/*
*~
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Website for NeoForged. Built using [Hugo](https://gohugo.io/).

## Development

Download or install [Hugo v0.118.2](https://github.com/gohugoio/hugo/releases/tag/v0.118.2). (The executable is self-contained.)
Download or install [Hugo](https://github.com/gohugoio/hugo/releases/latest). (The executable is self-contained.)

To build the website, run `hugo`. The site files will be found in the `public` directory.

Expand Down
86 changes: 86 additions & 0 deletions assets/js/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const VERSIONS_ENDPOINT = "https://maven.neoforged.net/api/maven/versions/releases/";
const FORGE_GAV = "net/neoforged/neoforge";
const LATEST_ENDPOINT = "https://maven.neoforged.net/api/maven/latest/version/releases/";
const DOWNLOAD_URL = "https://maven.neoforged.net/releases";
const GITHUB_URL = "https://github.com/neoforged/NeoForge";

async function loadChangelog() {
let gav = FORGE_GAV;
let fn = "neoforge";
let mcvers;

let currentMcVersionUrl = new URL(LATEST_ENDPOINT + encodeURIComponent(gav));
let versionJson;

try {
const response = await fetch(currentMcVersionUrl);
versionJson = await response.json();
} catch (error) {
if (error instanceof SyntaxError) {
console.log("There was a SyntaxError parsing the JSON response from the maven server.", error);
} else {
console.log("There was an error processing the request for a new version.", error);
}
}

if (versionJson) {
const { version } = versionJson;
mcvers = "1." + version.slice(0, 4);

const vs = `.changelog_body`;
const changelogUrl = `${DOWNLOAD_URL}/${gav}/${encodeURIComponent(version)}/${fn}-${encodeURIComponent(version)}-changelog.txt`;
const response = await fetch(`${changelogUrl}`);
const data = (await response.text()).split("\n");

const resultArray = [];

data.forEach(line => {
if (line.startsWith(" - ")) {
const lineVersion = line.substring(line.indexOf("`") + 1, line.indexOf("`", line.indexOf("`") + 1));
const installerUrl = `${DOWNLOAD_URL}/${gav}/${lineVersion}/${fn}-${lineVersion}-installer.jar`;
line = line.replace("`" + lineVersion + "`", `<a href="${installerUrl}" class="changelog_version"><code>${lineVersion}</code></a>`);

line = line.replace(" - ", `<li class="changelog_item" title="Install ${lineVersion} for Minecraft ${mcvers}">`);
UltimatChamp marked this conversation as resolved.
Show resolved Hide resolved
line += "</li>";

const pr = line.substring(line.indexOf("(#") + 2, line.indexOf(")", line.indexOf("(#")));
line = line.replace(`(#${pr})`, `<a class="pr-link" href="${GITHUB_URL}/pull/${pr}">(#${pr})</a>`);

const mcBadgeText = line.substring(line.indexOf("[") + 1, line.indexOf("]", line.indexOf("[")));
line = line.replace(`[${mcBadgeText}]`, `<font class="badges badges_mc">${mcBadgeText}</font>`);
} else if (line != "") {
if (line != " ") {
line = "▸" + line;
}

line = `<li class="changelog_item_desc">` + line + `</li>`
line = line.replace("Co-authored-by:", `<font class="badges badges_coauth">Co-authored-by</font>`)
}

line = line.replace(/`([^`]+)`/g, `<code>$1</code>`);

if (line.includes("#")) {
const startIndex = line.indexOf("#") + 1;
let endIndex = line.indexOf(" ", startIndex);

if (endIndex === -1) {
endIndex = line.length - 5; // exclude </li>
}

const issue = line.substring(startIndex, endIndex);
if (!isNaN(issue)) {
line = line.replace(`#${issue}`, `<a href="${GITHUB_URL}/issues/${issue}">#${issue}</a>`);
}
}

resultArray.push(line);
});

const result = resultArray.join("\n");

document.querySelector(vs).innerHTML = `
<h2><code>${encodeURIComponent(version)}</code> for Minecraft ${mcvers}</h2><hr>
<div class="changelog">${result}</div>
`;
}
}
27 changes: 14 additions & 13 deletions assets/js/neoforge.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const VERSIONS_ENDPOINT = 'https://maven.neoforged.net/api/maven/versions/releases/'
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'
const VERSIONS_ENDPOINT = "https://maven.neoforged.net/api/maven/versions/releases/"
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"
// 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
// For legacy version(s): https://maven.neoforged.net/api/maven/latest/version/releases/net/neoforged/forge?filter=1.20.1
// To filter a specific MC version: https://maven.neoforged.net/api/maven/latest/version/releases/net/neoforged/neoforge?filter=20.4

async function loadLatestVersions(minecraftVersions) {
for (const mcVersion of minecraftVersions) {
let gav = FORGE_GAV;
Expand All @@ -15,6 +16,7 @@ async function loadLatestVersions(minecraftVersions) {
let badges_beta = "";
let badges_new = "";
let badges_legacy = "";
let changelogUrl = "/changelog";

let currentMcVersionUrl = new URL(LATEST_ENDPOINT + encodeURIComponent(gav));
let versionJson;
Expand All @@ -24,25 +26,24 @@ async function loadLatestVersions(minecraftVersions) {
versionJson = await response.json();
} catch (error) {
if (error instanceof SyntaxError) {
console.log('There was a SyntaxError parsing the JSON response from the maven server.', error);
console.log("There was a SyntaxError parsing the JSON response from the maven server.", error);
} else {
console.log('There was an error processing the request for a new version.', error);
console.log("There was an error processing the request for a new version.", error);
}
}

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];
mcvers = "1." + version.slice(0, 4);
}
if (version.includes("beta")) {
badges_beta = `<font class="badges badges_beta">BETA</font>`;
}
const vs = `#filelist${mcVersion}`.split('.').join("");

const vs = `#filelist${mcVersion}`.split(".").join("");
const installerUrl = `${DOWNLOAD_URL}/${gav}/${encodeURIComponent(version)}/${fn}-${encodeURIComponent(version)}-installer.jar`;
const changelogUrl = `${DOWNLOAD_URL}/${gav}/${encodeURIComponent(version)}/${fn}-${encodeURIComponent(version)}-changelog.txt`;


document.querySelector(vs).innerHTML = `
<details${dropDown_VAL}>
<summary class="fileinfo__header">${badges_beta} ${badges_new} ${badges_legacy} NeoForge <code>${version}</code> for Minecraft ${mcvers}</summary>
Expand Down
7 changes: 7 additions & 0 deletions content/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "Latest Changelog"
draft: false
author: neoforgedteam
---

{{< changelog >}}
5 changes: 5 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ theme = ["hugo-notice", "mainroad"]
cached = true
twitter = "NeoForged_MC"

[[Params.widgets.social.custom]]
title = "NeoForged Project Listing"
url = "https://projects.neoforged.net/"
icon = "svg/projects.svg"

[[Params.widgets.social.custom]]
title = "GitHub"
url = "https://github.com/neoforged/"
Expand Down
17 changes: 17 additions & 0 deletions layouts/shortcodes/changelog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ if not ( .Page.Scratch.Get "nfJS") }}
Copy link
Member

Choose a reason for hiding this comment

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

you sure about this scratch stuff? At least call it changelogJS.

Copy link
Contributor Author

@UltimatChamp UltimatChamp Jan 6, 2025

Choose a reason for hiding this comment

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

On doing some research, this line is required to ensure that the js file is included only once on a page...? So I guess you're right.

{{ $js:= resources.Get "js/changelog.js" }}
<script src="{{ $js.RelPermalink }}"></script>
{{ .Page.Scratch.Set "nfJS" "hi" }}
{{ end }}

<div class="changelog_body" id="changelog">
<pre class="changelog"></pre>
</div>

<script>
document.addEventListener("readystatechange", evt=>{
if (evt.target.readyState === "complete") {
loadChangelog();
}
});
</script>
38 changes: 36 additions & 2 deletions themes/mainroad/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ figure.meta__icon {
display: inline-block;
padding: 10px 15px;
font-weight: 700;
border-radius: 0.2rem;
}

/* Pager (prev/next links) navigation */
Expand Down Expand Up @@ -1139,9 +1140,40 @@ summary code:hover {
font-family: monospace;
}

/* Installer Badges */
.badges_beta, .badges_new, .badges_legacy {
/* Badges */
.badges {
padding: 0 5px;
border-radius: 4px;
font-family: monospace;
}

/* Changelogs */
.changelog_body {
display: block;
padding: 0;
padding: 1.25rem;
margin-bottom: 20px;
margin-bottom: 1.25rem;
border-radius: 4px;
max-height: 825px;
overflow: auto;
}

.changelog_item {
border-radius: 5px;
padding: 0 4px;
}

.changelog_version code:hover {
text-decoration: underline;
filter: brightness(.85);
}

.changelog_item_desc {
list-style-type: none;
border-radius: 5px;
margin-left: 20px;
padding: 0 4px;
}

/* News Section */
Expand Down Expand Up @@ -1389,6 +1421,7 @@ a.anchor-wrapper:hover, a.anchor-wrapper:focus {
--color-code-notice: #e57;
--color-code-notice-background: #ffffff85;
--color-code-block-background: #2e3135;
--color-changelog-background: #bdc7c7;
--color-footer-text: #aab0b3;
--color-footer-link-text: #bdc7c7;
--color-ends-background: #323232;
Expand Down Expand Up @@ -1419,6 +1452,7 @@ a.anchor-wrapper:hover, a.anchor-wrapper:focus {
--color-code-notice: #e57;
--color-code-notice-background: #2e3135;
--color-code-block-background: #2e3135;
--color-changelog-background: #2e3135;
--color-footer-text: #aab0b3;
--color-footer-link-text: #bdc7c7;
--color-ends-background: #222222;
Expand Down
6 changes: 0 additions & 6 deletions themes/mainroad/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
{{- end }}

<link rel="shortcut icon" href="{{ "favicon.ico" | relURL }}">
{{- if not .Site.IsServer }}
{{- if hasPrefix .Site.GoogleAnalytics "G-" }}
{{ template "_internal/google_analytics.html" . }}
{{- else }}
{{- end }}
{{- end }}
<script src="{{ "js/modetoggle.js" | relURL }}"></script>
</head>
<body class="body">
Expand Down
28 changes: 28 additions & 0 deletions themes/mainroad/layouts/partials/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,34 @@ details:hover {
border: 2px solid var(--color-border-badges-legacy);
}

/* Changelogs */
.changelog_body {
background-color: var(--color-changelog-background);
}

.badges_mc {
background-color: var(--color-badges-new);
border: 2px solid var(--color-border-badges-new);
}

.badges_coauth {
background-color: var(--color-badges-legacy);
border: 2px solid var(--color-border-badges-legacy);
color: var(--color-text);
}

.changelog_item:hover {
background-color: var(--color-border);
}

.changelog_item_desc:hover {
background-color: var(--color-background);
}

.changelog_item_desc {
color: var(--color-meta-caption);
}

/* News Section */
.news {
border-top: 3px solid var(--color-border);
Expand Down
2 changes: 1 addition & 1 deletion themes/mainroad/layouts/partials/comments.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if and .Site.DisqusShortname (index .Params "comments" | default "true") (not .Site.IsServer) }}
{{ if and .Site.Config.Services.Disqus.Shortname (index .Params "comments" | default "true") (not hugo.IsServer) }}
<section class="comments">
{{ template "_internal/disqus.html" . }}
</section>
Expand Down
1 change: 1 addition & 0 deletions themes/mainroad/layouts/partials/svg/projects.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading