Skip to content

Commit 82a3be2

Browse files
committed
Improve renderRevisionLink
1 parent ccee590 commit 82a3be2

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

web/src/utils/general.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,33 @@ export function isVersionLE(v: string, ref: string): boolean {
248248
}
249249

250250
export function renderRevisionLink(versionRaw: string) {
251-
const match = versionRaw.match(/r(\d+)/);
252-
if (!match) return versionRaw;
251+
if (!versionRaw) return versionRaw;
252+
253+
let revisionNumber: string | null = null;
254+
let matchedText: string | null = null;
255+
256+
// Case 1: rNNNNN
257+
const matchR = versionRaw.match(/r(\d+)/i);
258+
if (matchR) {
259+
revisionNumber = matchR[1];
260+
matchedText = matchR[0];
261+
}
262+
263+
// Case 2: versions like 1.5.5-9.13999 → take last .number
264+
if (!revisionNumber) {
265+
const matchVersion = versionRaw.match(/(\d+)(?!.*\d)/);
266+
if (matchVersion) {
267+
revisionNumber = matchVersion[1];
268+
matchedText = matchVersion[0];
269+
}
270+
}
271+
272+
if (!revisionNumber || !matchedText) return versionRaw;
253273

254-
const revisionNumber = match[1];
255-
const beforeRevision = versionRaw.slice(0, match.index);
256274
const url = `https://buildinfo.mtasa.com/?Author=&Branch=&Revision=${revisionNumber}`;
257275

258-
return `${beforeRevision}<a href="${url}" target="_blank" rel="noopener noreferrer">r${revisionNumber}</a>`;
259-
}
276+
return versionRaw.replace(
277+
matchedText,
278+
`<a href="${url}" target="_blank" rel="noopener noreferrer">${matchedText}</a>`
279+
);
280+
}

0 commit comments

Comments
 (0)