fix: updates page sorting — correct version typo 971→97.1 and add semver tiebreaker

This commit is contained in:
2026-05-09 23:47:50 +08:00
parent 5ed60ef3cc
commit 6718f1b033
2 changed files with 19 additions and 5 deletions
@@ -1,7 +1,7 @@
--- ---
title: "Submit Bug Fix & Game Card Layout Fix" title: "Submit Bug Fix & Game Card Layout Fix"
date: "2026-05-09" date: "2026-05-09"
version: "2026.0.971" version: "2026.0.97.1"
summary: "Fixed submit wizard crash when creating new game versions and game card height issue in grid views." summary: "Fixed submit wizard crash when creating new game versions and game card height issue in grid views."
--- ---
+18 -4
View File
@@ -37,16 +37,30 @@ function getSlugs(): string[] {
.map((file) => file.replace(/\.md$/, "")) .map((file) => file.replace(/\.md$/, ""))
} }
function compareVersion(a: string, b: string): number {
const pa = a.split(".").map(Number)
const pb = b.split(".").map(Number)
const len = Math.max(pa.length, pb.length)
for (let i = 0; i < len; i++) {
const na = pa[i] ?? 0
const nb = pb[i] ?? 0
if (na !== nb) return nb - na // descending
}
return 0
}
export function getAllUpdates(): UpdateMeta[] { export function getAllUpdates(): UpdateMeta[] {
const slugs = getSlugs() const slugs = getSlugs()
const updates = slugs.map((slug) => { const updates = slugs.map((slug) => {
const { meta } = getUpdateMeta(slug) const { meta } = getUpdateMeta(slug)
return meta return meta
}) })
// Sort by date descending (newest first) // Sort by date descending, then by version descending (newest first)
return updates.sort( return updates.sort((a, b) => {
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime(), const dateDiff = new Date(b.date).getTime() - new Date(a.date).getTime()
) if (dateDiff !== 0) return dateDiff
return compareVersion(a.version, b.version)
})
} }
function getUpdateMeta(slug: string): { meta: UpdateMeta } { function getUpdateMeta(slug: string): { meta: UpdateMeta } {