Skip to content

Commit

Permalink
feat: more features to the changelog
Browse files Browse the repository at this point in the history
* fix the changelog in light mode
* ability to install a specific version from the changelog
* make changelog version descriptions more differentiable
* support for issue links and code blocks in the changelog
* also fix compat with the latest Hugo
  • Loading branch information
UltimatChamp committed Dec 13, 2024
1 parent 4b30412 commit 8c90369
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
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
37 changes: 29 additions & 8 deletions assets/js/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ async function loadChangelog() {
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);
}
}

Expand All @@ -36,22 +36,43 @@ async function loadChangelog() {

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

const lineVersion = line.substring(line.indexOf('`') + 1, line.indexOf('`', line.indexOf('`') + 1));
line = line.replace("`" + lineVersion + "`", `<code>${lineVersion}</code>`);
line = line.replace(" - ", `<li class="changelog_item" title="Install ${lineVersion} for Minecraft ${mcvers}">`);
line = 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 {
line = `<li class="changelog-item-desc">` + line + `</li>`
} 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);
});

Expand Down
16 changes: 8 additions & 8 deletions assets/js/neoforge.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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?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
Expand All @@ -26,9 +26,9 @@ 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);
}
}

Expand All @@ -41,7 +41,7 @@ async function loadLatestVersions(minecraftVersions) {
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`;

document.querySelector(vs).innerHTML = `
Expand Down
18 changes: 16 additions & 2 deletions themes/mainroad/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,21 @@ summary code:hover {
font-family: monospace;
}

.changelog-item-desc {
.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;
padding-left: 20px;
border-radius: 5px;
margin-left: 20px;
padding: 0 4px;
}

/* News Section */
Expand Down Expand Up @@ -1412,6 +1424,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 @@ -1442,6 +1455,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
2 changes: 1 addition & 1 deletion themes/mainroad/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{- end }}

<link rel="shortcut icon" href="{{ "favicon.ico" | relURL }}">
{{- if not .Site.IsServer }}
{{- if not hugo.IsServer }}
{{- if hasPrefix .Site.GoogleAnalytics "G-" }}
{{ template "_internal/google_analytics.html" . }}
{{- else }}
Expand Down
12 changes: 10 additions & 2 deletions themes/mainroad/layouts/partials/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ details:hover {

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

.badges_mc {
Expand All @@ -414,7 +414,15 @@ details:hover {
color: var(--color-text);
}

.changelog-item-desc {
.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);
}

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

0 comments on commit 8c90369

Please sign in to comment.